c++ - Get pointer to class method with 'using' keyword -
i'm using visual studio 2010.
why can't pointer class method "upgraded" public in child class?
the following code not compile:
#include <iostream> #include <functional> class parent { protected: void foo() { std::cout << "parent::foo()\n"; } }; class child : public parent { public: //void foo() { parent::foo(); } //this compiles using parent::foo; //this not compile }; int main() { child c; std::function < void () > f = std::bind(&child::foo, &c); f(); return 0; }
it gives error:
error c2248: 'parent::foo' : cannot access protected member declared in class 'parent'
it compiles here.
i think forgot add c++11 option in compiler.
for example, gcc it's -std=c++11
or -std=gnu++11
.
edit : seems here using alias declaration not implemented in visual studio version.
in fact, here people talks compiler bug.
the weird thing here is:
c.foo(); // works fine std::function < void () > f = std::bind(&child::foo, &c); // won't compile
Comments
Post a Comment