![](https://img-blog.csdnimg.cn/20201014180756780.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
C++易入的坑
hujianglang
记录所见所思,便于回顾反思。
展开
-
C++进阶:新人易入的那些坑 --1.常量、常指针和指针常量
/*why use consta)Guards against inadvertent write to the variableb)Self documentingc)Enables compiler to do more optimization,making code tighter,fasterd)const means the variable can be put in R...翻译 2018-09-24 23:14:55 · 102 阅读 · 0 评论 -
C++进阶:新人易入的那些坑2-常量和函数
//const used with functionsclass Dog{ int age; string name;public: Dog() { age = 3; name = "dummy"; } //const parameters void setAge(const int& a) { age = a;} void setAge(int& a) { a...翻译 2018-09-25 20:25:41 · 108 阅读 · 0 评论 -
C++进阶:新人易入的那些坑 --3.逻辑常量与比特位常量
class BigArray{ vector<int> v; //huge vector mutable int accessCounter;//method one int flag; int*v2;//another int arraypublic: int getItem(int index) const { accessCounter++; co...翻译 2018-09-25 20:46:24 · 508 阅读 · 0 评论 -
C++进阶:新人易入的那些坑 --4.编译器生成的函数
//########################################################################/*Compiler silently writes 4 functions if they are not explicitly declared1.Copy constructor2.Copy Assignment Operator3....翻译 2018-09-25 22:02:30 · 164 阅读 · 0 评论 -
C++进阶:新人易入的那些坑 --5.不让编译器生成的函数
/*Compiler silently writes 4 functions if they are not explicitly declared:1.Copy constructor.2.Copy Assignment Operator.3.Destructor4.Default constructor*/class OpenFile{public: OpenFi...翻译 2018-09-27 21:45:14 · 151 阅读 · 0 评论 -
C++进阶:新人易入的那些坑 --6.虚析构和智能析构函数
/*use virtual destructors in polymorphic base classes*///方案一class Dog{public: virtual ~Dog() { cout << "Dog destroyed" << endl; } virtual void bark() {}};class Yellowdog :...翻译 2018-09-27 22:23:31 · 117 阅读 · 0 评论 -
C++进阶:新人易入的那些坑 --7.析构函数中的异常处理
/*Prevent Exceptions from Leaving Destructors*/class dog{public: string m_name; dog(string name) { m_name = name; cout << name << "is born." << endl; } ~dog() { co...翻译 2018-09-27 22:24:16 · 230 阅读 · 0 评论 -
C++进阶:新人易入的那些坑 --8.杂项
/*定义:一个函数自己直接调用或间接调用自己*///P8构造和析构函数中的虚函数/*Calling Virtual Function in Constructor or Destructor*/class Dog{public: Dog() { cout << "dog born." << endl; //bark(); } virt...翻译 2018-10-10 22:38:38 · 190 阅读 · 0 评论