代码
#include <iostream>
using namespace std;
class example
{
public:
example()
{
cout<<"Default Constructing! "<<endl;
}
example(int n)
{
i=n;
cout<<"Constructing: "<<i<<endl;
}
~example()
{
cout <<"Destructing: "<<i<<endl;
}
int get_i()
{
return i;
}
private:
int i;
};
int sqr_it(example o)
{
return o.get_i()* o.get_i();
}
int main()
{
example x(10);
cout<<x.get_i()<<endl;
cout<<sqr_it(x)<<endl;
return 0;
}
运行结果:
知识点总结:
别忘了不是类的函数
学习心得:
好好学习 天天向上