F
Fred Mangusta
Hi,
I have a class D1 derived from a base class B. I also have some methods
that accept either a pointer to D1 or a pointer by reference to D1, as in
bool method1(D1* &d1_);
bool method2(D1* d1_);
//etc..
This worked well, until I discovered that I need to apply the same
methods on ANOTHER class derived from B, D2.
Since I was hoping it might be possible to use the same methods I use
for D1, (without creating duplicates) I redefined all these methods in
order that they will accept B instead of D1. I thought this was a "more
general" version of these methods. So I had
bool method1(B* &b_);
bool method2(B* b_);
//etc..
The problem is, nothing works any more. The compiler complains if I pass
pointers of D1 or D2 to the "more generic" methods:
"no matching function for call to.."
I was considering the possibility of casting the D1/D2 pointer to a B
pointer through dynamic_cast, but I don't know if this is the correct
approach. Will I still be able to manipulate D1-specific or D2-specific
features from within the method, if I pass a B-downcast pointer to it?
What do you suggest to do?
Thanks a lot
F.
I have a class D1 derived from a base class B. I also have some methods
that accept either a pointer to D1 or a pointer by reference to D1, as in
bool method1(D1* &d1_);
bool method2(D1* d1_);
//etc..
This worked well, until I discovered that I need to apply the same
methods on ANOTHER class derived from B, D2.
Since I was hoping it might be possible to use the same methods I use
for D1, (without creating duplicates) I redefined all these methods in
order that they will accept B instead of D1. I thought this was a "more
general" version of these methods. So I had
bool method1(B* &b_);
bool method2(B* b_);
//etc..
The problem is, nothing works any more. The compiler complains if I pass
pointers of D1 or D2 to the "more generic" methods:
"no matching function for call to.."
I was considering the possibility of casting the D1/D2 pointer to a B
pointer through dynamic_cast, but I don't know if this is the correct
approach. Will I still be able to manipulate D1-specific or D2-specific
features from within the method, if I pass a B-downcast pointer to it?
What do you suggest to do?
Thanks a lot
F.