Deepesson
Deepesson

Reputation: 39

Trying to receive a template in a struct and use it on a std::vector

I'm trying to create a tree class to a test, but I'm getting: "error: type/value mismatch at argument 1 in template parameter list for 'template class std::vector".

template <typename T>
struct a {
T data;
void ReceiveData(T T_data) {
    data = T_data;
}
};
struct b {
std::vector<a> b_data;//Error here
};

Upvotes: 1

Views: 76

Answers (1)

Oblivion
Oblivion

Reputation: 7374

You need to specify the template type of a:

template<typename T> struct a 
{
   T data;
   void ReceiveData(T T_data) 
   {
      data = T_data;
   }
};

template<typename T> struct b 
{
   std::vector<a<T>> b_data; //compiles now
   //          ^^^^
};

Note that a alone is not a type, it is a template. Live on Godbolt

Upvotes: 4

Related Questions