I have this simple code:
class A {
public:
string toString() const { return "A"; }
};
class B : public A {
public:
string toString() const { // some code here }
};
I want toString() in class B will inherit from class A and take some extra values. In this example, will be: “AB” (A: from class A, and B: extra string).
This is easy in Java, but I don’t know how to do in C++. My first idea is take string from toString() in class A and append additional string. So, to take this: I use: static_cast<A>(const_cast(this))->toString() but it won’t work 🙁
Please help me. Thanks 🙂
In MS implementation (on Windows) you can do __super::toString() instead, but that’s a non-portable MS extension.