请教个javascript的问题 (转载)# Programming - 葵花宝典
n*s
1 楼
code :
class Base{
public:
Base(){cout << "Base()" << endl;}
Base(const Base&){cout << "Base(const Base&)" << endl;}
~Base(){cout << "~Base()" << endl;}
};
Base func(Base b){return b;}
void test1(){
Base a;
func(a);
}
void test2(){
Base a;
Base b = func(a);
}
int main(){
test1();
cout<test2();
return 0;
}
// from the output,
test1() will
1. first call Base's default constructor for "Base a"
2. call Base's copy constructor since parameter is passed by value
3. call Base
class Base{
public:
Base(){cout << "Base()" << endl;}
Base(const Base&){cout << "Base(const Base&)" << endl;}
~Base(){cout << "~Base()" << endl;}
};
Base func(Base b){return b;}
void test1(){
Base a;
func(a);
}
void test2(){
Base a;
Base b = func(a);
}
int main(){
test1();
cout<test2();
return 0;
}
// from the output,
test1() will
1. first call Base's default constructor for "Base a"
2. call Base's copy constructor since parameter is passed by value
3. call Base