Last active
          August 29, 2015 14:07 
        
      - 
      
- 
        Save wallstop/e1439e6647be0efb9dc1 to your computer and use it in GitHub Desktop. 
    Temp.cpp
  
        
  
    
      This file contains hidden or 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
    
  
  
    
  | 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