I am trying some funky stuff here...
So, my question is, why do I have to call the operator as a function, instead of as an operator? Can I get around this?Code:template<class t> class b { public: b(){} t* operator()(int x) { return objs[x]; } void Add(t* p) { objs.push_back(p); } private: std::vector<t*> objs; }; template<class t> class a { public: a(){} b<t>* operator->() { return &m_b; } private: b<t> m_b; }; ... int main() { a<plug> plugs; plugs->Add(&plug()); plugs->Add(&plug_derived()); plugs->(0)->print(); // ugly compile time error here... plugs->operator()(0)->print(); // just fine... }
Z.




Reply With Quote