That looks like an unsafe downcast. Regardless, I'm seeing more concerning issues with your design than that.
Let's talk about inheritance and polymorphism in C++. Consider an abstract base class which defines nothing more than the interface to the family of related types:
1 2 3 4 5
|
struct Shape
{
virtual void draw() const = 0;
virtual ~Shape() {}
};
|
Now, consider a couple subclasses, which define the draw method:
1 2 3 4
|
struct Circle : public Shape
{
virtual void draw() const { /* draw implementation */ }
};
|
1 2 3 4
|
struct Square : public Shape
{
virtual void draw() const { /* draw implementation */ }
};
|
Now, the virtual method draw, called through the base class abstraction (interface), will perform the appropriate action to draw itself. The abstractions can be treated uniformly, without trying to determine what type it really is or performing any casting. For example:
1 2 3 4 5 6 7
|
// perhaps this exists in some kind of aggregate class
typedef vector<Shape *> Container;
Container c;
//...
for( Container::const_iterator i = c.begin(); i != c.end(); ++i ) {
(*i)->draw(); // draw the shape
}
|
Now, just because I've been doing some interesting reading lately, I'll hit this example with some more detailed design theory. Note that when possible an abstract base class should have no members. It is certainly possible to combine a concrete base with an abstraction but doing so adds a few subtle (during implementation) limitations. Formally called the Dependency Inversion Principle
1 (DIP), recommends "pushing policy (interfaces) up and implementation down." The idea is to have the implementation depend on the abstraction rather than the typical contradiction.
1 Item 36, in C++ Coding Standards: 101 Rules, Guidelines, and Best Practices by Herb Sutter and Andrei Alexandrescu