Skip to content

Instantly share code, notes, and snippets.

@arithma arithma/someobjectpriv.cpp
Last active Jun 12, 2019

Embed
What would you like to do?
Secret Interface Passing at Construction
class SomeObjectPrivate {
public:
void sensitive() {
}
};
class SomeObject : private SomeObjectPrivate {
SomeObject(void (*callback)(SomeObjectPrivate)) {
// setup SomeObject
// this will work, since the object itself knows
// that it is actually SomeObjectPrivate as well.
// though passing back this interface this early
// might be problematic since am not sure if
// passing this back out before SomeObject constructor
// returns is undefined behavior or some such, but it
// illustrates the idea at least
callback(this);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.