O
Osaman
Hello
I am having difficulty getting polymorphism to kick in as I thought it
should
after a clone. Here is the scenario.
Let's say I have a base class "b" with derived classes "d1" and "d2".
My method
gets passed in an a parameter which tells me whether it is a d1 or a
d2 (inputSelection) and an object (inputObject). So I end up with
b tmp;
switch(inputSelection){
case 1:
tmp = (d1) inputObject.clone();
break;
case 2:
tmp = (d2) inputObject.clone();
break;
....
}
tmp.methodFoo(arg1, arg2,...etc)
the methodFoo that is being called here is the one declared inside
class b,
not the overridden one in classes d1 or d2. How can I get the
appropriate
methodFoo to be called ? Note that the only reason I was using the
switch
statement above was "to help" get tmp to be of the appropriate derived
class.
It would have been cleaner to even be able to just do
tmp = (b) inputObject.clone();
but I'm not sure if that will work or not...
Thanks
Osa
I am having difficulty getting polymorphism to kick in as I thought it
should
after a clone. Here is the scenario.
Let's say I have a base class "b" with derived classes "d1" and "d2".
My method
gets passed in an a parameter which tells me whether it is a d1 or a
d2 (inputSelection) and an object (inputObject). So I end up with
b tmp;
switch(inputSelection){
case 1:
tmp = (d1) inputObject.clone();
break;
case 2:
tmp = (d2) inputObject.clone();
break;
....
}
tmp.methodFoo(arg1, arg2,...etc)
the methodFoo that is being called here is the one declared inside
class b,
not the overridden one in classes d1 or d2. How can I get the
appropriate
methodFoo to be called ? Note that the only reason I was using the
switch
statement above was "to help" get tmp to be of the appropriate derived
class.
It would have been cleaner to even be able to just do
tmp = (b) inputObject.clone();
but I'm not sure if that will work or not...
Thanks
Osa