Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- class Base
- {
- public:
- virtual void init() = 0;
- };
- class Impl : public Base
- {
- char m_data[ 2 ];
- public:
- virtual void init()
- {
- m_data[ 0 ] = 'c';
- m_data[ 1 ] = 'x';
- }
- };
- Base* getInstance()
- {
- Base* res = new Impl();
- res->init();
- return res;
- }
- struct Extractor
- {
- char data[ 10 ];
- };
- int main()
- {
- Base* b = getInstance();
- Extractor* ext = (Extractor*)( b );
- cout << "1 byte " << ext->data[ sizeof( void* ) +0 ] << endl;
- cout << "2 byte " << ext->data[ sizeof( void* ) +1 ] << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment