c++ - Determining the type from a smart pointer -
i have function takes in 2 template parameters. 1 expected smart pointer, , other expected object type. example, smartptr<myobject>
first template parameter , myobject
second template parameter.
template <typename t, typename tobject>
i know whether can determine second parameter, myobject
, automatically first parameter smartptr<myobject>
or not template function written this:
template <typename t>
and type tobject
in original template function automatically determined t
expected smart pointer.
as requested, here function declaration , use:
template <typename t, typename tobject> t* createormodifydoc(t* doc, myhashtable& table) { t* ptr = null; if (!table.findelement(doc->id, ptr)) { table.addelement(doc->id, new tobject()); table.findelement(doc->id, ptr); } return ptr; }
if know first template parameter smart pointer type, why not declare function 1 parameter , use such:
template<typename t> void whatisit(smartptr<t> ptr) { printf("it a: %s" typeid(t).name()); }
Comments
Post a Comment