Template specialization: C++ templates that only a

2019-08-15 18:23发布

I want to make a simple message template class as follows. I followed the structure verbatim from the chosen answer posted here. However, this seems to break in Visual Studio 2013.

template<typename T> Message;

template<> Message <std::vector<uint8_t>>
{
public:

};

template<> Message <std::string>
{

};

IntelliSense tells me that Message is not a template.

Placing class before Message in the forward declaration results in a slightly better, but equally annoying IntelliSense error: expected and identifierafter the opening brace { of each template.

template<typename T> class Message;

template<> Message <std::vector<uint8_t>>
{
public:

};

template<> Message <std::string>
{

};

I should note that all the above code is currently being placed in a header file.

1条回答
不美不萌又怎样
2楼-- · 2019-08-15 18:38

You need to include the class keyword in the template specialization as well. I don't know why the linked answer doesn't do that.

template<typename T> class Message;

template<> class Message <std::vector<uint8_t>>
{
public:

};

template<> class Message <std::string>
{

};
查看更多
登录 后发表回答