PDA

View Full Version : declaring inside an if...



ImpactDNI
05-16-2003, 01:38 PM
alright, i know this is a C++ question, but i like u guys here, and you help quickly =P
alright, i have a program i have to make for school... but im stuck, i have a menu (cout << enter number....; cin >> choice;" right, and i have an if right after that for which choice they made...
i have a class called "MyVec, and i have overloaded it, so i can pass MyVec Vect(); MyVec Vect(x); MyVec Vect(x,y);... this is based off the choice (1,2,3)...
if its one, i want to just go "MyVec Vect();" if 2: "MyVec Vect(x)" etc.
the problem is, when i declare them INSIDE the if statements, then they are LOCAL TO THE IF!!! in other words, i cant pass them anyplace else...
anyone wanna help me?

shinpaughp
05-16-2003, 02:32 PM
MyVec *vec;

switch(blah)
{
case 1:
vec = new MyVec();
break;
case 2:
vec = new MyVec(bleh);
break;
...
}