A
al.cpwn
class test {
public:
test()
:a(0)
{
}
int get() { return a; }
test(const test& t)
:a(t.get())
{
}
void modify()
{
a++;
}
private:
int a;
};
Intuitively it seems that the parameter to copy constructor should be
const test&
However, if I try to use get() method, my compiler gives the error:
i:\Documents and Settings\Al Cpwn\My Documents\Visual Studio
Projects\c++\1.cpp(11) : error C2662: 'test::get' : cannot convert
'this' pointer from 'const test' to 'test &'
Can someone please help me understand why?
public:
test()
:a(0)
{
}
int get() { return a; }
test(const test& t)
:a(t.get())
{
}
void modify()
{
a++;
}
private:
int a;
};
Intuitively it seems that the parameter to copy constructor should be
const test&
However, if I try to use get() method, my compiler gives the error:
i:\Documents and Settings\Al Cpwn\My Documents\Visual Studio
Projects\c++\1.cpp(11) : error C2662: 'test::get' : cannot convert
'this' pointer from 'const test' to 'test &'
Can someone please help me understand why?