PDA

View Full Version : how to swap two different class objects using void pointers in c++



mandlakoteswar2011
23rd April 2016, 06:54
hai

i have class A and Class B along with two objects

A a1;
B b1;

(void *)

so i want to swap two objects using void pointer

Can anyone help me...do the needful asap

anda_skoa
23rd April 2016, 14:10
What do you mean with swap? swap what?

What is the situation you want to arrive at?

Cheers,
_

d_stranz
23rd April 2016, 18:12
You mean you want to do something like this?



A * a = new A();
B * b = new B();

A * c = (A *)( void * )b;


You might be able to fool the compiler into accepting code like that, but what do you think will happen when you try to execute a member function of class A when the variable c actually points to an instance of class B?