2016年6月29日

C++ 类的继承三(继承中的构造与析构)

摘要: //继承中的构造与析构 #include using namespace std; /* 继承中的构造析构调用原则 1.子类对象在创建时会首先调用父类的构造函数 2.父类构造函数执行结束后,执行子类的构造函数 3.当父类的构造函数有参数时,需要在子类的初始化列表中显示调用 4.析构函数调用的先后顺序与构造函数相反 继承与其他类做成员变量混搭的情况下,构造和析构调用原则 1.先构造父类,在构造... 阅读全文

posted @ 2016-06-29 22:15 寒魔影 阅读(496) 评论(0) 推荐(0)

C++ 类的继承二(赋值兼容性原则)

摘要: //赋值兼容性原则 #include using namespace std; class PointA{ public: PointA(){ x = 0; y = 0; } void Set(){ } private: int x; int y; }; class PointB :public PointA{... 阅读全文

posted @ 2016-06-29 21:37 寒魔影 阅读(1004) 评论(0) 推荐(0)

C++ 类的继承一(访问控制)

摘要: //类的继承 #include using namespace std; /* 面向对象中的继承类之间的父子关系 1.子类拥有父类所有的成员属性和成员函数(包括私有成员变量) 2.子类就是一种特殊的父类 3.子类对象可以当作父类对象使用 4.子类可以拥有父类没有的方法和属性 c++中的类成员访问级别(public,protected,private) 类成员访问级别设置原则 1.需要被外界... 阅读全文

posted @ 2016-06-29 20:46 寒魔影 阅读(4806) 评论(0) 推荐(1)

C++ 匿名对象产生场景

摘要: //匿名对象产生的三种场景 #include using namespace std; class Point{ public: Point(int a,int b){ cout x = a; this->y = b; } Point(Point &a1){ cout x = a1.x; this->y =... 阅读全文

posted @ 2016-06-29 10:37 寒魔影 阅读(1216) 评论(0) 推荐(0)

导航