c++ - Is this the correct way of using a void* member pointer? -
c++ - Is this the correct way of using a void* member pointer? -
can utilize method dosomething this; first having assigned pointer class void* fellow member of b?
class { public: a(int); int m_x; int dosomething(){}; }; class b { public: void* m_y; }; #include "x.h" using namespace std; a::a(int x) { m_x = x; } int main() { //create 2 pointers , b b *b; *a; b = new b(); = new a(15); b->m_y = a; ((a*)b->m_y)->dosomething(); delete a; delete b; homecoming 0; }
stay away void*
why not have pointer a in b (or even, b owns instance of a), or b holds smart pointer instance of a - there many other better ways of doing things.
c++
Comments
Post a Comment