Concentric
Expert Member
- Joined
- Feb 16, 2017
- Messages
- 1,028
- Reaction score
- 197
Can someone help me with the best practice when it comes to accessing member functions of a derived class?
As below, i want to access the member function of the derived class, but unless i do something like
The only thing i could think of is to have all possible functions of derived classes as virutal funcitons in the base class.
Thanks
As below, i want to access the member function of the derived class, but unless i do something like
<static_cast> which i dont think is good practice, i cant figure out what the best way to do it is.The only thing i could think of is to have all possible functions of derived classes as virutal funcitons in the base class.
C++:
class Shape
{
public:
Shape();
virtual void draw() = 0;
}
class Circle: public Shape
{
public:
Circle();
void draw();
void setProperty1(int size);
private:
int m_property1;
}
Shape* shape = new Circle;
shape->setProperty1(12); //Not possible
Thanks
Last edited: