**如果赋值操作=左右值相等,即自我赋值,传统做法:
证同策略:**
为防止new异常,需要在new之前不删除原先的引用:
swap技术的运用:
当传递的是值不是引用时同样可用swap:
注意:...
分类:
其他好文 时间:
2015-05-18 20:49:32
阅读次数:
162
由于很久没有搞内存管理了,很多细节都忘记了今天项目要用到operatordelete重载到DLL,发现了问题,网上搜索以后,再对比以前写的代码,发现了问题:原来MSVC默认的operatornew(size_t)和operatordelete(void*)虽然可以重载,但是不能封装到DLL中,编译会...
分类:
其他好文 时间:
2015-05-18 20:16:06
阅读次数:
147
大约遇到下面的问题 Expected identifier or ‘(‘ Unknown type name ‘NSString‘ Unknown type name ‘Protocol‘ ... 还有NSString.h、NSZone.h、NSObject.h也会提示类似的错误,根据此链接,我定位到问题原因为引入...
分类:
其他好文 时间:
2015-05-18 16:59:44
阅读次数:
277
PHP Datatype Conversion Safety Risk、Floating Point Precision、Operator Security Risk、Safety Coding Principle
分类:
Web程序 时间:
2015-05-18 14:31:26
阅读次数:
177
二、核心——断言断言是编写测试用例的核心实现方式,即期望值是多少,测试的结果是多少,以此来判断测试是否通过。1. 断言核心方法assertArrayEquals(expecteds, actuals)查看两个数组是否相等。assertEquals(expected, actual)查看两个对象是否相...
分类:
其他好文 时间:
2015-05-18 12:45:36
阅读次数:
216
Taha has got a standard deck of cards with him. In addition to the 52 regular ones, there are 2 joker cards. Every regular card has a rank and a suit. The ranks in ascending order are: A, 2, 3, 4, 5, 6...
分类:
其他好文 时间:
2015-05-18 09:10:39
阅读次数:
163
题目描述:Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.解题思路:把除数表示为:dividend = 2^i * diviso...
分类:
编程语言 时间:
2015-05-16 13:23:04
阅读次数:
267
每个类只有一个析构函数,但可以由多个构造函数。
对于一个类,如果程序员不显式的声明定义上述函数,编译器自动的产生4个inline函数,
A();A(const A& );~A(); A& operator=(const A& )
1.不要在构造函数内做与初始化无关的工作,不要在析构函数内做与销毁对象无关的工作。
注意初始化和赋值的区别
初始化:在对象创建的同时使用初值直接填充对象...
分类:
其他好文 时间:
2015-05-16 09:13:19
阅读次数:
111
// 深赋值与浅赋值
// 浅赋值,这样的浅赋值会导致程序崩溃,与浅拷贝一个理
#include
using namespace std;
class S_Evaluate;
ostream& operator<<(ostream& out, const S_Evaluate &s);
class S_Evaluate
{
friend ostream& operator<<(ostre...
分类:
编程语言 时间:
2015-05-15 21:28:51
阅读次数:
162
// 浅拷贝与深拷贝
// 像这样的浅拷贝会导致程序崩溃,因为同一个空间被释放了两次
#include
#include
using namespace std;
class S_Copy;
ostream& operator<<(ostream& out, const S_Copy &s);
class S_Copy
{
friend ostream& operator<<(ostr...
分类:
编程语言 时间:
2015-05-15 17:41:50
阅读次数:
99