#include<iostream>
class circle
{
public:
circle(int a,int b)
{
r=a;
p=b;
std::cout<<"构造函数调用完毕"<<std::endl;
}
~circle(){std::cout<<"析构函数调用完毕"<<std::endl;}
int getr()
{
return r;
}
int getp()
{
return p;
}
private:
int r;
int p;
};
double face(circle a)
{
double b;
b=3.14159*(a.getr())*(a.getr());
return b;
}
void main()
{
circle cobj(3,4);
std::cout<<cobj.getp()<<std::endl;
std::cout<<cobj.getr()<<std::endl;
std::cout<<face(cobj)<<std::endl;;
circle cobq(5,6);
std::cout<<face(cobq)<<std::endl;;
}
为什么调用了四次析构函数?
class circle
{
public:
circle(int a,int b)
{
r=a;
p=b;
std::cout<<"构造函数调用完毕"<<std::endl;
}
~circle(){std::cout<<"析构函数调用完毕"<<std::endl;}
int getr()
{
return r;
}
int getp()
{
return p;
}
private:
int r;
int p;
};
double face(circle a)
{
double b;
b=3.14159*(a.getr())*(a.getr());
return b;
}
void main()
{
circle cobj(3,4);
std::cout<<cobj.getp()<<std::endl;
std::cout<<cobj.getr()<<std::endl;
std::cout<<face(cobj)<<std::endl;;
circle cobq(5,6);
std::cout<<face(cobq)<<std::endl;;
}
为什么调用了四次析构函数?