64,643
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
class Person{
public:
Person(){
cout << "no param contructor!" << endl;
mAge = 10;
}
Person(int age){
cout << "param constructor!" << endl;
mAge = age;
}
Person(const Person& person){
cout << "copy constructor!" << endl;
mAge = person.mAge;
}
~Person(){
cout << "destructor!" << endl;
}
public:
int mAge;
int mId;
};
Person MyBusiness(){
Person q(10);
cout << "MyBusiness_q:" << (int*)&q << endl;
q.mId = 200;
return q;
}
int func()
{
int a = 10;
cout << "func_a:" << &a << endl;
return a;
}
int main(){
Person p = MyBusiness();
cout << "main_p:" << (int*)&p << endl;
cout << "mId:" << p.mId << endl;
int b= func();
cout << "main_b::" << &b << endl;
return 0;
}
Person p = MyBusiness();
Person p = MyBusiness();
Person(const Person& person) {
cout << "copy constructor!" << endl;
mAge = person.mAge;
}
cout << "mId:" << p.mId << endl;
class Foo {
public:
int N = 0;
~Foo() {
}
Foo() {
}
};
Foo GetFoo() {
Foo foo = Foo();
foo.N = 10;
return foo;
}
int main()
{
Foo foo = GetFoo();
int n = foo.N;
return 0;
}