In my class Js::Object I've an operator() overload which returns Js::JType*
all Other Classes in Js Namespace e.g. Js::Number, Js::String etc.. even Js::Object inherits from Js::JType
Code:
Js::JType* &operator()(const string& key);
source
Code:
/**
typedef std::map<string, Js::JType*> ElemMap;
*/
Js::JType* &Js::Object::operator()(const string& key){
ElemMap::iterator it=list.find(key);
if(it != list.end()){
return (Js::JType* &)(it->second);
}else{
Js::JType* x = new Js::JType;
list.insert(make_pair(key, x));
return x;
}
}
and this is how I am using it.
Code:
Js::Object o;
o("math") = new Js::String("Hello World");
Now If everything is ok.
Code:
o("math")->commit()
should return "Hello World" (with quotes as std::string)
then it will invoke Js::String::commit()
But Its invoking Js::JType::commit()
and thus its returning null (as std::string)
e.g. in other words its invoking the commit() of grand parent Class not of the intended class.
and yes commit is virtual.
Hope I am able to clarify the problem.