Hello everyone,
Which C++ rule do I break in the following code? Why there is compile error?
Code:class Foo{ public: Foo() { } int foo1() { return 100; } const Foo getCurrent1() { return *this; } const Foo& getCurrent2() { return *this; } }; int main() { Foo f; f.getCurrent1().foo1(); // error C2662: 'Foo::foo1' : cannot convert 'this' pointer from 'const Foo' to 'Foo &' f.getCurrent2().foo1(); // error C2662: 'Foo::foo1' : cannot convert 'this' pointer from 'const Foo' to 'Foo &' return 0; }
thanks in advance,
George



LinkBack URL
About LinkBacks




CornedBee