2016-06-29 1 views
-3

По моему previous question, я хотел бы сделать следующее:Добавление параметров для передачи объявленная шаблоны

#include <vector> 
#include<string> 
#include <cstdint> 

template<typename T> class Message; 

template<> class Message <std::vector<uint8_t>> 
{ 
public: 
    const T getKey() { return key; }; 
    const T getMessage() { return message; }; 

protected: 
    T key; 
    T message; 
}; 

Однако IntelliSense говорит мне, что identifier "T" is undefined"

Что я делаю неправильно?

ответ

2

Вы должны заменить T на std::vector<uint8_t> повсюду в вашей специализации:

template<> class Message <std::vector<uint8_t>> 
{ 
public: 
    const std::vector<uint8_t>& getKey() const { return key; }; 
    const std::vector<uint8_t>& getMessage() const { return message; }; 

protected: 
    std::vector<uint8_t> key; 
    std::vector<uint8_t> message; 
}; 

Я также добавить недостающие const и ссылки.

+1

Можно также добавить 'using T = std :: vector ;' statement. – skypjack

Смежные вопросы