user2191818 user2191818 - 1 year ago 91
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 Source

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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download