Please reffer below ::
class Base{
public:
Base(){ printf("Base class condructr invoked\n");}
void execute();
int common();
~Base() { printf("Base detructor\n");}
};
void Base::execute(){
int x=0;
x=common();
printf("%d \n value \n",x);
}
int Base::common(){
int m = 10;
return 10;
}
In the above example code I want to use the
execute function of the base class & local variables, this Base class is used in lots of place meant lots of classes have derived this.
Now I want to use this Base class and when execute is callled I wante
my common funtion to be called, wanted to know whether
it is feasible to change the base class function name common to virtual<this will not impact any other code>
or to do the following way??
class Derived:: public Base{
public:
virtual int common();
}
int Derived :: common(){
return 20;
}
can I declare function by virtual in the derived class is this accetable??
since I am new to C++ devell.. I i dont want mess up with exising large chunk of code..I hope I above is clear
please do suggest, thanks in advance