Skip to content

Instantly share code, notes, and snippets.

@jeremyroman
Created May 2, 2017 01:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeremyroman/65c35d170d60dd322f6f96b3b7ee728e to your computer and use it in GitHub Desktop.
Save jeremyroman/65c35d170d60dd322f6f96b3b7ee728e to your computer and use it in GitHub Desktop.
public/private API class trick
namespace blink {
class RealClass : public RealBase {
public:
static RealClass* Create();
void DoSomething();
private:
// members here
};
namespace agent {
class AgentClass : public AgentBase {
public:
AgentClass* Create();
void DoSomething();
// no data members; not a real class
};
AgentClass* AgentClass::Create() {
ScriptWrappable* self = RealClass::Create();
return reinterpret_cast<AgentClass*>(self);
}
void AgentClass::DoSomething() {
RealClass* self = static_cast<RealClass*>(reinterpret_cast<ScriptWrappable*>(this));
self->DoSomething();
}
} // namespace agent
} // namespace blink
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment