⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 inher_copy.cpp

📁 在进行C++培训时
💻 CPP
字号:
#include<iostream>
using namespace std;
class B{
     public:
	       B();
	       B(int i);
		   //B(B& x);
	       ~B();
	       virtual void Print() const;
     private:
	       int b;
};
B::B()
{	b=10;
	cout<<"B's default constructor called."<<endl;
}
B::B(int i)
{	b=i;
    cout<<"B's constructor called." <<endl;
}
//B::B(B& x)
//{
//	b=x.b;
//	cout<<"B' copy constructor called."<<endl;
//}

B::~B()
{	cout<<"B's destructor called."<<endl;  }
void B::Print() const
{	cout<<b<<endl;  }
class C:public B
{
    public:
      C();
	  C(int i,int j);
	  C(C& cc);
	  ~C();
	  virtual void Print() const;
	private:
	  int c;
};
C::C()
{	c=0;
	cout<<"C's default constructor called."<<endl;
}
C::C(int i,int j):B(i)
{	c=j;
	cout<<"C's constructor called."<<endl;
}
C::C(C& cc)//:B(cc)
{
	c=cc.c;
	cout<<"C's copy constructor called."<<endl;
}

C::~C()
{	cout<<"C's destructor called."<<endl; }
void C::Print() const
{	B::Print();	cout<<c<<endl;  }
void fn1(C x)
{
	x.Print();
}
void main()
{	

	C obj(5,6);
	

	fn1(obj);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -