绝不重新定义继承来的缺省值 首先明确下,虚函数是动态绑定,缺省参数值是静态绑定 // a class for geometric shapes class Shape { public: enum ShapeColor { Red, Green, Blue }; // all shapes must offer a function to draw themselves ; ... }; class Rectangle: public Shape { public: // notice the…
#include <iostream> #include <cstdlib> using namespace std; class Pen { public: ) { cout<<"write with color:"<<color<<endl; } }; class Pencil : public Pen{ public: ) { cout<<"write with color:"<&l…
class A { int a; int b; int c; public: A(int aa, int bb) : a(aa), b(bb),c(0) { cout << "aa bb" << endl; } A(int aa, int bb, int cc); }; 上面类中,已经有一个构造函数,形参有两个,我们又重载一个有3个形参的构造函数,为了减少代码量,就想着让3个参数的构造函数调用2个参数的构造函数,然后在执行一些自己的代码,这就如同派生类先调用基类…