user2191818 user2191818 - 2 months ago 13
C++ Question

Define template class itself to a type

I am learning template knowledge and find some template usage like

template<typename T> struct myclass
{
...
typedef myclass type;
...
}


From my understanding, I can only use "myclass" with T specified. Like

myclass<int> member;


Now it defines "myclass" to "type" without specifing the T, so I would like to know in which case "type" will be used.

An example will be really appreciated.

Answer

Inside of the body of myclass<T>, the identifier myclass is a synonym for myclass<T>, so the line is equivalent to:

typedef myclass<T> type;