I have an issue trying to use a class I defined. Here's the issue. I have a class definition:
class test {
public test (); //default constructor
public test (int var1, int var2); //constructor #2
public ~test();
public func1 (void);
...
};
and in my main () I am doing:
main (){
int testvar = 3;
if ( testvar > 0 ) {
test myvar ( 2, 1 );
}
myvar.func1();
}
But the trouble is, by the time the "if" is executed, the destructor of myvar has already destroyed the object myvar. How can I get around this issue? I want to define an object in an if statement and be able to still use it after the if is finished.
Any ideas?
Thanks


Sign In
Create Account


Back to top









