Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
Runtime overriding of virtual functions
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Kai-Uwe Bux, post: 1495733"] Sounds like you want to hack a setWidget() method from the outside. One idea would be to do something like void setWidget( B& b, A* a ) { char * b_data = (char*) &b; // and now do some manipulations to b_data[...] to // set the field b.m_a } For instance, on my machine the following program #include <iostream> class B{ private: unsigned int l; public: unsigned int get( void ) { return( l ); } }; // B void set ( B& b, unsigned int k ) { char* b_data = (char*) &b; char* k_data = (char*) &k; for ( int i = 0; i < 4; ++i ) { b_data[i] = k_data[i]; } } int main ( void ) { B b; std::cout << b.get() << std::endl; set( b, 6 ); std::cout << b.get() << std::endl; } prints 3221224484 6 I would think, however, that the setWidget() method was left out for a reason and that you are very likely to break all sorts of stuff inside the object b. Hope this helps Kai-Uwe Bux[/i][/i] [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
Runtime overriding of virtual functions
Top