I have an abstract class (parent) and just created derived class (child) from it as below:
class parent {
public:
virtual string print()=0;
};
template<class T>
class child: public parent{
private:
unordered_map<string, parent*> children;
public:
parent *&operator[](string name) {
return children[name];
}
virtual string print(){
//some jobs...
}
}
ok. Now i used derived class like below:
child<string> a;
a["test"]->print();
and the problem shows out.
I think the problem is that unordered_map::[] operator creates an instance of parent class rather than child class that I want.
How can tell unordered_map to create new items as child < string >