c++ - Problems writing a function template for a map of object pointers -
i have function template print map of string object pointers:
//template function print map of pointers template <class t2> void printmap(std::map<string, t2*>&_map) { //test print line cout << "test function template map print" << endl; std::map<string, t2*>::iterator iter; (iter = _map.begin(); iter != _map.end(); iter++) { //call print function type iter->second->print(); } }
i trying implement it:
printmap<myobject>(std::map<string, myobject*>&mymapofobjects);
i getting
"error type name not allowed"
i getting error on linux server ; expected before iter , iter undeclared.
i have tested files basic function template , functions beingness passed file, it's way written function, it's not happy doing. have been working on few days , unable find solution, sure obvious experienced programmers, thanks.
another question: can pass string separate type, have t1 , t2, template<class t1, class t2>
can utilize template sorts of maps, ie ints?
your syntax wrong calling function. can this:
printmap(mymapofobjects);
and compiler deduce template arguments. or, if you'd rather explicit it:
printmap<myobject>(mymapofobjects);
the std::map<string, myobject*>&
text not belong in invocation.
c++ templates pointers map function-templates
No comments:
Post a Comment