I have a function that currently accepts two template parameters. One of them is expected to be a smart pointer, and the other is expected to be an object type. For example, SmartPtr<MyObject>as the first template parameter and MyObjectas the second template parameter.
template <typename T, typename TObject>
I would like to know if I can determine the second parameter MyObjectautomatically from the first parameter SmartPtr<MyObject>or not so that my template function is written as follows:
template <typename T>
And the type TObjectin the original template function is automatically determined from T, which is expected to be a smart pointer.
As requested, here is the function declaration and its 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;
}
source
share