return与析构函数
#include <iostream>
using namespace std;
class a{
private:
int i;
public:
a(int n):i(n){
cout<<"constructing"<<endl;
}
~a(){
cout<<"destructing"<<endl;
}
int get_i(){
return i;
}
};
int aqr_it(a a){
return a.get_i()*a.get_i();
}
int main(){
a a(10);
cout<<a.get_i()<<endl;
cout<<aqr_it(a)<<endl;
return 0;
using namespace std;
class a{
private:
int i;
public:
a(int n):i(n){
cout<<"constructing"<<endl;
}
~a(){
cout<<"destructing"<<endl;
}
int get_i(){
return i;
}
};
int aqr_it(a a){
return a.get_i()*a.get_i();
}
int main(){
a a(10);
cout<<a.get_i()<<endl;
cout<<aqr_it(a)<<endl;
return 0;
}
结果:
constructing
10
100
destructing
destructing