>can I have some sort of if statement in my_func saying "it's of type CDer_a, do this, or no, it's of type CDer_b, do this"?
Is this not the point of virtual functions? You could do something with typeinfo (or even using a overrided string) to get info of the type -
Code:
#include <iostream>
#include <typeinfo>
using namespace std;
class CBase {
public:
virtual void my_func () {
cout << typeid(*this).name() << '\n';
}
int data;
};
class CDer_a : public CBase
{
public:
int data;
};
class CDer_b : public CDer_a
{
public:
float data;
};
int main()
{
CDer_a a;
a.my_func();
CBase b;
b.my_func();
return 0;
}
However, this would be less efficient than using virtual functions.