Let's say I have two classes like the following:
Class A
{
public:
..
private:
int length;
}
Class B: public Class A
{
public:
..
private:
float length;
}
What I would like to know is:
There is a class that satisfies my needs and I want to reuse it. However for my program needs, its data members should be of another type.
I have some books, but all of them refer only to overriding of base class member methods.
You can use templatized members i.e., generic members instead of overriding the members.
You can also declare a VARIANT(COM) like union.
struct MyData
{
int vt; // To store the type
union
{
LONG lVal;
BYTE bVal;
SHORT iVal;
FLOAT fltVal;
.
.
}
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With