Created
September 6, 2011 16:47
-
-
Save dmatveev/1198132 to your computer and use it in GitHub Desktop.
Invoking a protected method from a PIMPL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo; | |
class Bar { | |
friend class Foo; | |
protected: | |
void aProtectedMethod() { | |
} | |
}; | |
class Foo { | |
class Impl { | |
public: | |
void invokeAProtectedMethod(Bar &b) { | |
b.aProtectedMethod(); /* <-- MSVS does not allow to do it here */ | |
} | |
}; | |
Impl *impl; | |
public: | |
Foo() : impl(new Impl) { | |
} | |
~Foo() { | |
delete impl; | |
} | |
void invokeAProtectedMethod(Bar &b) { | |
impl->invokeAProtectedMethod(b); | |
} | |
struct Baz { | |
void invokeAProtectedMethod(Bar &b) { | |
b.aProtectedMethod(); | |
} | |
}; | |
}; | |
int main (int argc, char *argv[]) { | |
Bar bar; | |
Foo foo; | |
foo.invokeAProtectedMethod(bar); | |
Foo::Baz baz; | |
baz.invokeAProtectedMethod(bar); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment