Quote Originally Posted by fsixteen View Post
Ok. then I have to put FlipUpCommand switchUp(*myobj); statement in each 'IF' which I do not want to do.
Then you could do something like
Code:
void *myobj = NULL;
Light *myLight;
Fan *myFan;

int choice;
cout<<"Select Light (1): ";
cout<<"Select Fan (2): ";
cin>>choice;

if (choice ==1)
{
        Light *myLight = new Light();
        myobj = (void*)myLight;
}
if (choice ==2)
{
       Fan *myFan = new Fan();
       myobj = (void*)myFan;
}
FlipUpCommand switchUp(*myobj);
Note that in such a case your FlipUpCommand class had to know what type of object (Light or Fan) was actually passed in and cast the void* pointer to corresponding class.