0

I want to store several structs in a vector, but the struct has a template so I get a compile error, how can I store the structs in the vector?

Example:

template<class First, class Second> struct foo
{
     First f;
     Second s;
};

std::vector<foo> bar; //error!
3
Contributors
3
Replies
4
Views
8 Years
Discussion Span
Last Post by StuXYZ
0

Yeah, I thought of that but I wanted to be able to use it to store any type of foo .

Is there not a way around this?

0

Yes certainly you can do that but you have to resolve the instance at some point. So perhaps you want it is another templated class.

template<class First, class Second> 
struct foo
{
     First f;
     Second s;
};

template<typename A,typename B>
struct Other
{
  std::vector< foo< A, B > > bar;
  std::vector< foo< B, B > > barX;
};

Note that you still have to have the compiler figure out the exact versions that you will need. You have only delayed the choise.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.