In C++ what does template<> mean?

前端 未结 3 1080
没有蜡笔的小新
没有蜡笔的小新 2021-01-31 18:33

It\'s not a syntax I\'m familiar with, but I saw it in another question, an example being:

template<> struct Allowed { };
3条回答
  •  甜味超标
    2021-01-31 19:04

    You might just say it is just the required syntax.

    The normal syntax would be template< typename T > struct Allowed;

    Because we know that in this case T is std::string there is nothing to put inside the angled brackets but the word template and the angled brackets are still required because writing struct Allowed on its own would not imply that you are specializing the template but simply that you are instantiating one with std::string as the type. (The word "struct" is not necessary to do that but is still permitted).

提交回复
热议问题