|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
#include<iostream>
using namespace std;
class base
{
base(string m_name, int m_age=0)
{
name = m_name;
age = m_age;
cout << "base的构造函数" << endl;
}
base(const base& p)
{
cout << "base的复制构造函数" << endl;
}
~base()
{
cout << "base的析构函数" << endl;
}
virtual void print()
{
cout << age<< endl;
}
protected:
string name;
int age;
};
class base1 :public base
{
public:
base1(string m_name, int m_age, int m_id);
virtual void print();
base1(const base1& p1)
{
cout << "base1的复制构造函数" << endl;
}
~base1()
{
cout << "base1的析构函数" << endl;
}
private:
int id;
};
base1::base1(string m_name, int m_age, int m_id) :base(m_name, m_age = 0)
{
id = m_id;
}
void base1::print()
{
cout << age << " " << id << endl;
}
int main()
{
} |
|