R
Raghu Kodali
Hi All,
I am trying to figure out any way to pass an evaluated variable to new?
Please let me know if it is possible.
Please see the example structure of my code as below
class baseclass
{
private:
int foo;
int bar;
public:
virtual void run_func(void)=0;
};
class derivclass_1ublic baseclass
{
private:
int xvz;
public:
void run_func(void) { /* do something interesting */}
};
I have the derived classes like derivclass_1,derivclass_2,derivclass_3
etc till derivclass_30
my present way of calling goes something like this
baseclass *bc;
if(x==1)
bc=new derivclass_1;
if(x==2)
bc=new derivclass_2;
if(x==3)
bc=new derivclass_3;
.....
......
if(x==30)
bc=new derivclass_30;
which is looking very inefficient to me.
I want to do SOMETHING like
bc=new derivclass_x;
which will save me alot of lines of code as well as helping me in
isolating the main code if I want to add derivclass_31 at a later point
of time.
Is it possible to do (somehow)?
Thanks
Raghu
I am trying to figure out any way to pass an evaluated variable to new?
Please let me know if it is possible.
Please see the example structure of my code as below
class baseclass
{
private:
int foo;
int bar;
public:
virtual void run_func(void)=0;
};
class derivclass_1ublic baseclass
{
private:
int xvz;
public:
void run_func(void) { /* do something interesting */}
};
I have the derived classes like derivclass_1,derivclass_2,derivclass_3
etc till derivclass_30
my present way of calling goes something like this
baseclass *bc;
if(x==1)
bc=new derivclass_1;
if(x==2)
bc=new derivclass_2;
if(x==3)
bc=new derivclass_3;
.....
......
if(x==30)
bc=new derivclass_30;
which is looking very inefficient to me.
I want to do SOMETHING like
bc=new derivclass_x;
which will save me alot of lines of code as well as helping me in
isolating the main code if I want to add derivclass_31 at a later point
of time.
Is it possible to do (somehow)?
Thanks
Raghu