#include<iostream>
using namespace std;
class CRectangle
{
public :
int w,h;
int Area(){
return w*h;
}
void Init(int w_, int h_){
w=w_;
h=h_;
}
};
int main()
{
int w,h;
CRectangle r;
cin>>w>>h;;
r.Init(w,h);
cout<<r.Area();
return 0;
}
#include<iostream>
using namespace std;
class Complex
{
private :
double real,image;//定义的实部和虚部;
public :
Complex(double r,double i);//构造函数;
Complex(int i);//类型转换构造函数;
void add(Complex c);
void show();
} ;
Complex::Complex(double r,double i)
{
real=r;
image=i;
}
Complex::Complex(int i)
{
real=i;
image=0;
}
void Complex::add(Complex c)
{
real+=c.real;
image+=c.image;
}
void Complex::show()
{
cout<<real<<"+"<<image<<"i";
}
int main()
{
Complex c1(3,5);
Complex c2=4.5;
c1.add(c2);
c1.show();
return 0;
}
对构造函数,复制构造函数,析构函数,类型转换构造函数的使用还不是很熟练,还没有很好的理解他们。
原文:https://www.cnblogs.com/obamax/p/8761866.html