Get pointer to class method with 'using' keyword
I'm using Visual Studio 2010.
Why can't I get a pointer to a class method which was "upgraded" to public
in a child class?
The following code does 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 does NOT compile
};
int main() {
Child c;
c.foo();
std::function < void () > f = std::bind(&Child::foo, &c);
return 0;
}
It gives the error:
error C2248: 'Parent::foo' : cannot access protected member declared in
class 'Parent'
No comments:
Post a Comment