unable to declare class without initialization?

Viewed 5460

For standard data objects such like int, the following can be done

    int number;
    number = 0;

Basically, you can declare number before initializing it, useful if you initialize inside various if statements and you don't want number going out of scope.

Can something similar be done with custom classes?

I have a class called mem_array with constructor of the form

    mem_array(int,int,std::string);

I would like to do the following

      mem_array myData;
      if(x==0) myData(1,1,"up");
      if(x==1) myData(0,0,"down");

basically, so I can use myData outside of the scope of the if statements. Can something like this be done?

7 Answers
Related