Created
May 2, 2017 01:14
-
-
Save jeremyroman/65c35d170d60dd322f6f96b3b7ee728e to your computer and use it in GitHub Desktop.
public/private API class trick
This file contains 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
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