|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- #include "iostream"
- using std::endl;
- using std::cout;
- using std::cin;
- class Object
- {
- protected:
- int a;
- int b;
- public:
- Object(int a, int b)
- {
- this->a = a;
- this->b = b;
- cout << "Object 构造执行" << endl;
- }
- public:
- ~Object()
- {
- cout << "Object 析构执行" << endl;
- }
- };
- class Parent :public Object
- {
- protected:
- char* p;
- public:
- Parent(char* p) :Object(1, 2)
- {
- this->p = p;
- cout << "父类的构造函数" << p << endl;
- }
- public:
- ~Parent()
- {
- cout << "父类的析构函数" << p << endl;
- }
- public:
- void printParent()
- {
- cout << "我是父亲" << endl;
- }
- };
- class Child :public Parent
- {
- protected:
- char* myp;
- Object obj1;
- Object obj2;
- public:
- Child(char* p) :Parent(p), obj1(3, 4), obj2(5, 6)
- {
- this->myp = p;
- cout << "子类构造函数" << myp << endl;
- }
- public:
- ~Child()
- {
- cout << "子类析构函数" << myp << endl;
- }
- public:
- void printChild()
- {
- cout << "我是儿子" << endl;
- }
- };
- void objPlay()
- {
- Child c("abdbnkhg");//问题 这里显示出错 我这代码照视频打的 视频上运行通过 我却运行不了 那个图片显示编译后的错误
- }
- void main()
- {
- objPlay();
- system("pause");
- }
复制代码 |
-
继承中的构造函数
|