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
sourceCode:Js::JType* &operator()(const string& key);
and this is how I am using it.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; } }
Now If everything is ok.Code:Js::Object o; o("math") = new Js::String("Hello World");
should return "Hello World" (with quotes as std::string)Code:o("math")->commit()
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.



LinkBack URL
About LinkBacks




. About not dying by memory leaks... well, memory leaks are still really bad. And yes, it *will* die from it if the program runs for too long. It's really advisable to fix it. A simple hack-fix would be to replace the pointers by reference counted pointers, which clean up their memory automatically if they are no longer required.
CornedBee