Effective C++ Item05 Note
来源:互联网 发布:哥布林升级数据 编辑:程序博客网 时间:2024/06/11 20:16
//Effective C++ Item05#include<iostream>#include<cstring>using namespace std;//声明一个empty class时,编译器会为它声明一个default构造函数,copy构造函数,一个copy assignment操作符和一个析构函数,所有这些函数都是public inline//编译器产出的析构函数是non-virtual的,除非base class自身声明有virtual构造函数class Empty{};//在class含有const或reference成员变量时编译器将不会为它声明copy assignment操作符//如果base class将copy assignment操作符声明为private,编译器也将拒绝为其derived class声明一个copy assignment操作符template<typename T>class NamedObject{public:NamedObject(std::string& name, const T& value) :nameValue(name),objectValue(value){//nameValue = name;//必须在member initialization list中初始化reference变量//objectValue = value;//const成员变量不能够赋值};private:std::string& nameValue;const T objectValue;};int main(){std::string newDog("Persephone");std::string oldDog("Satch");NamedObject<int> p(newDog, 2);NamedObject<int> s(oldDog, 36);//p = s;//C++不允许让reference改指向不同对象,编译会出现operator=不可用的错误}
0 0
- Effective C++ Item05 Note
- 《Effective C++》 Reading Note 1
- 《Effective C++》 Reading Note 2
- 《Effective C++》 Reading Note 3
- 《Effective C++》 Reading Note 4
- Effective C++ Item02 Note
- Effective C++ Item03 Note
- Effective C++ Item04 Note
- Effective C++ Item06 Note
- Effective C++ Item07 Note
- Effective C++ Iem08 Note
- Effective C++ Item09 Note
- Effective C++ Item11 Note
- Effective C++ Item12 Note
- Effective C++ Item13 Note
- Effective C++ Note
- Reading note of Effective C++
- Effective C++ (reading note)
- ADS “At least one file could not be added to the selected target(s)”
- GitHub秘籍
- Spring-学习笔记(ContextLoaderListener)
- 从尾到到打印链表
- eclipse自动切换到dubug视图,设置eclipse调试自动跳转
- Effective C++ Item05 Note
- 容斥原理学习之路【容斥原理】
- C++ 实参和形参 交换变量值
- tap gesture recognizer关联到一image view笔记********
- 从点滴看管理之电话沟通技巧
- 有奖征文--我亲历的京东发展史
- 给SHBrowseForFolder 添加“新建文件夹”按钮
- Android 记住密码和自动登录界面的实现(SharedPreferences 的用法)
- 段式存储管理