if (choice ==1){
Light *myobj = new Light();
}
FlipUpCommand switchUp(*myobj);
Error: `myobj' undeclared (first use this function)
Please advice how to solve this problem without changing the Light class.
Scope of "myobj" is if-block, so outer code can't access it. You should move myobj out.
1 2 3 4 5 6 7
|
Light *myobj = NULL;
if (choice ==1)
{
Light *myobj = new Light();
}
if(myobj)
FlipUpCommand switchUp(*myobj);
|
Last edited on
Sorry for my inattention. coder777 is right, of course, no second pointer inside must be declared.