C++问题,confusing...# Programming - 葵花宝典
g*e
1 楼
#include
using namespace std;
class A{
int i; // a mark to show the difference
public:
A(int ii=1):i(ii){} // default constructor
A(const A& a) {i=a.i+1;} // copy constructor,just increase i by 1
int ivalue() const {return i;} //the function to show the mark
};
A func1(const A& a){
return a;
}
A func2(const A& a){
A b(a.ivalue());
return b;
}
int main(){
A a;
A b=func1(a);
A c=func2(a);
using namespace std;
class A{
int i; // a mark to show the difference
public:
A(int ii=1):i(ii){} // default constructor
A(const A& a) {i=a.i+1;} // copy constructor,just increase i by 1
int ivalue() const {return i;} //the function to show the mark
};
A func1(const A& a){
return a;
}
A func2(const A& a){
A b(a.ivalue());
return b;
}
int main(){
A a;
A b=func1(a);
A c=func2(a);