Once I was trying to create an object inside a switch statement. It looked something like this.
cout >> "Enter how many objects you want to create: ";
int nofobjects;
cin << nofobjects;
switch(numberofobjects) {
case 1:
objectclass object1;
break;
case 2:
objectclass object1;
objectclass object2;
break;
case 3:
cout << "Whoa, thats too many!"
break;
but when I compiled the program it said that I DID NOT declare the objects.
This is probably because if they user types 3 the objects will not be created and they will be created only if they type 1 or 2. So I was thinking of a workaround for this.
I couldn't find one. This just popped up in my head and I still can't think of the solution. So what do you supposed to do when this happens. Is there like a workaround or trick like using if-else form (by the way I tried it and it did not work either).