You are first defining myobj as a pointer to the class Light. You are then defining myobj as a pointer to the class Fan. You now have two definitions for myobj which are different - which the language/compiler does not allow. You are trying to have myobj as either a pointer to Light or a pointer to Fan depending upon choice and then passing myobj as a parameter to switchUp. Unless Light/Fan are derived from the same base class and you are trying an example for polymorphism then I suspect your design is wrong. What is the defintion of switchUp? and what are you trying to achieve?