0

Hello all,
I'm having a bit of trouble with this program I'm working on. I have a base class, we'll call it Base, and two nearly identical Derived classes, only one of which is relevant. I created a pointer (Base *BP), and pointed it to Derived &DO. I need to downcast it so that it can access the Derived class's member functions (or, rather, just one, called setType(string), but that's the idea). I spent hours troubleshooing and researching casting, but can't quite figure out what's wrong. Any help would be appreciated.

Here's basically what it looks like:

Base *BP;

BP = new Derived();
Derived *DO = dynamic_cast<Derived *>(BP);


BP->setType("hello");

This results in getting a "error: class Base has no member named setType"


Thank you for your time.

2
Contributors
1
Reply
2
Views
8 Years
Discussion Span
Last Post by mitrmkar
0

Shouldn't you rather be calling the setType() through the DO pointer instead of BP (assuming that the Base class does not and is not intended to have a setType() method), i.e.
DO->setType("hello");
should work.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.