Skip to content

Instantly share code, notes, and snippets.

@wallstop
Last active August 29, 2015 14:07
Show Gist options
  • Save wallstop/e1439e6647be0efb9dc1 to your computer and use it in GitHub Desktop.
Save wallstop/e1439e6647be0efb9dc1 to your computer and use it in GitHub Desktop.
Temp.cpp
class BaseClass
{
public:
BaseClass();
virtual ~BaseClass();
virtual void whoAmI()
{
std::cout << "I'm BaseClass!" << std::endl;
}
protected:
int m_int;
};
class DerivedClassA : public BaseClass
{
public:
DerivedClassA();
~DerivedClassA();
void whoAmI()
{
std::cout << "I am DerivedClassA!" << std::endl;
}
private:
char m_char;
}
BaseClass* b = new DerivedClassA();
b->whoAmI(); // "I am DerivedClassA!"
BaseClass* a = new BaseClass();
a->whoAmI(); // "I am BaseClass!"
/*
So the challenge is: Create a serialization method (this needs to be virtual, which is fine).
It returns some kind of IOStream, similar to a bitbuffer. The challenge: Decode the bitbuffer
and instantiate (new) the proper instance/type of class.
In the above, BaseClass would only use 4 bytes of memory (on a 32 bit system) for m_int.
DerivedClassA needs 5 bytes (on a 32 bit system) for m_int (4) + m_char ( 1).
Additional bytes may be necessary for self-awareness, although they should be minimal.
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment