Results 1 to 1 of 1
Here is a code snippet:
class test{
public:
test(){
cout<<"I am in default constructor ";
}
static void func(const test &obj){
cout<<"I am in function ";
}
protected:
test( const ...
- 02-03-2011 #1Just Joined!
- Join Date
- Feb 2011
- Posts
- 1
C++ constructor/copy constructor issues in g++ 3.4.6
Here is a code snippet:
class test{
public:
test(){
cout<<"I am in default constructor ";
}
static void func(const test &obj){
cout<<"I am in function ";
}
protected:
test( const test &o){
cout<<"I am in copy constructor ";
}
};
int main() {
test::func(test());
}
The above code gives following error with g++ 3.4.6(on Red Hat Linux) on compilation: In function int main()': error:test::test(const test&)' is protected
error: within this context
However if you compile with g++ 3.3.2 or g++ 4.4.3 (on Red Hat Linux),it compiles successfully and gives following output:
I am in default constructor I am in function
In the above code,i have passed the temporary object(created by default constructor) to function func by reference.So why the compiler 3.4.6 is calling the copy constructor?


Reply With Quote