c++中类与类之间继承需要注意

来源:互联网 发布:软件项目经理证书挂靠 编辑:程序博客网 时间:2024/05/18 02:27
#include<iostream>
/**
如果想要子类自动调用父类的构造函数
父类则必须提供无参构造函数 
*/
class Fruit
{
public:
Fruit()
{
cout<<"我是Fruit类默认的无参构造函数"<<endl; 
}
std::string s;
};
class Apple:public Fruit{
  public:
  Apple(){  // Apple()::Fruit() {}
  cout<<"我是Apple类默认的无参构造函数"<<endl; 
 }
};
int main()
{
Apple apple;
return 0;
}
0 0
原创粉丝点击