并不相同!!
!number%2 != !(number%2)
uint size_t
uint
//is short of unsigned int, which is pretty much universally 32 bits
size_t
//is the “size matching the largest possible address range you can use in the machine”
uint 32位不变,size_t跟计算机一样位数。。
在构造函数中使用另一个构造函数来初始化
class Foo() { ...; }
//--- erro: mem-initializer of 'Foo::m_val' follows constructor delegation
class Foo(int val): Foo() , m_val(val) {}
由其他构造函数来代理,则默认由另一个构造函数来初始化所有成员
solution:
class Foo(int val):m_val(val) {}
class Foo():Foo(0) {}
使用模板类作为基类
template <class T>
class Base
{
protected:
T _x;
};
template <class T>
class More: public Base<T>
{
T getX() { return _x; }//在vs中通过编译,g++则编译失败, error:_x未声明
}
写一个继承自模板基类的模板类时,不能直接使用名称来引用基类的成员
需要告诉编译器在哪里查找名称
solution:
template <class T>
class More: public Base<T>
{
T getX() { return this->_x; }
}
纯虚析构函数
在基类中,即使把虚函数作为纯虚函数,仍然需要定义
因为子类必须调用基类的析构函数