Can you explain this member function template?
Any one help me by explaining the real use of function templates. How to they work? This morning I saw some code but i still don't understand the real use of this:
class A
{
template<class T> T getData() const
{
const T* pointer == dynamic_cast<const T*>(mData)
if(0 == pointer)
{
T defaultValue = T()
}
}
private:
LData *mData;
};
I don't understand anything of this. Can anyone give me a general idea about function templates?
Th开发者_JAVA技巧anks
I think the should be something like this:
class A
{
template<class T>
T getData() const
{
const T* pointer = dynamic_cast<const T*>(mData);
if(0 == pointer)
return T();
return *T;
}
private:
LData *mData;
};
It's trying to get the mData converting that buffer or class (I don't know what LData is) in a T type.
this article may be usefull:
http://www.codersource.net/c/c-tutorial-on-templates/c-templates-function-templates.aspx
精彩评论