Skip to content

Instantly share code, notes, and snippets.

@dmatveev
Created September 6, 2011 16:47
Show Gist options
  • Save dmatveev/1198132 to your computer and use it in GitHub Desktop.
Save dmatveev/1198132 to your computer and use it in GitHub Desktop.
Invoking a protected method from a PIMPL
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