C++ (Qt)class A{public: void set(QString s) { str = s; } QString get() { return str; } protected: QString str;}; class B : public A{public: void set(QString s){ str = s; } void setB(QString s){ strB = s; } QString get(){ return str; } QString getB(){ return strB; } protected: QString strB; }; class C : public A{public: void set(QString s){ str = s; } void setC(QString s){ strC = s; } QString get(){ return str; } QString getC(){ return strC; } protected: QString strC; }; int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); QMap<QString, A> map; B b; b.set("class B set"); C c; c.set("class C set"); map.insert("B",b); map.insert("C",c); QString bb = map["B"].get(); QString cc = map["C"].getC(); // error: 'class A' has no member named 'getC' qDebug() << map.size() << " " << bb << " " << cc; return a.exec();}
QMap<QString,A*> map;...QString cc= (static_cast<C*>(map["C"]))->getC();