How can I protect derived classes from breaking when I change the internal parts of the base class? A class has two distinct interfaces for two distinct sets of clients: It has a public interface that serves unrelated classes It has a protected inter…
A derived class inherits all of the members of a base class except for its constructors. You must define a constructor in a derived class unless the base class has defined a default (parameterless) constructor.  If you don’t define a constructor in t…
There is a base class at the root of the hierarchy, from which the other class inherit, directly or indirectly. These inheriting classes are known as derived calsses. The key ideas in Object-Oriented Programming are data abstraction, inheritance and…
In C++, once a member function is declared as a virtual function in a base class, it becomes virtual in every class derived from that base class. In other words, it is not necessary to use the keyword virtual in the derived class while declaring rede…
Effective C++ chapter 2. 构造 / 析构 / 赋值运算 (Constructors, Destructors, and Assignment Operators) Item 5. 了解 C++ 默默编写并调用哪些函数 (Know what functions C++ silently writes and calls) 当 C++ 处理过一个 empty class (空类)之后,其便不再是一个 empty class.如果你自己没有声明,编译器就会为它声明(编译器版本的…
什么时候empty class(空类)不再是个empty class呢?当C++处理过它之后,是的,如果你自己没有声明,编译器就会为它声明(编译器版本)一个copy构造函数.一个copy assignment操作符和一个析构函数.此外如果你没有声明任何构造函数,编译器也会为你声明一个default构造函数.所有这些都是public且inline. 编译器所生成的copy assignment操作符,其行为基本上与copy构造函数如出一辙,但一般而言只有当生出的代码合法且有适当机会证明它有意义,编…
条款5:了解C++默默编写并调用哪些函数 记住: ★编译器可以(仅仅是可以,并非必须,仅当程序中有这样的用法时才会这么做!!!)暗自为class创建default构造函数,copy构造函数,copy assignment操作符以及析构函数. ---------------------------------------------------------------------------------------------------------------------------------…
我根据自己的理解,对原文的精华部分进行了提炼,并在一些难以理解的地方加上了自己的"可能比较准确"的「翻译」. Chapter 6 继承与面向对象设计 Inheritance and Object-Oriented Design 条款32: 确定你的public继承塑模出is-a关系 以C++进行面向对象编程,最重要的一个规则是:public inheritance(公开继承)意味着"is-a"(是一种)的关系.请牢记这个规则! 如果你令class D(Derived…
本文转自:https://msdn.microsoft.com/en-us/data/jj591617#1.2 When working with Entity Framework Code First the default behavior is to map your POCO classes to tables using a set of conventions baked into EF. Sometimes, however, you cannot or do not want t…
<Item 9> Never call virtual functions during construction or destruction 1.you shouldn't call virtual functions during construction or destruction, because the calls won't do what you think, and if they did, you'd still be unhappy. If you're a recov…