Compiler Error: Passing std::vector<T2> to Function Taking std::vector<T1>

Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 2K views
ehrenfest
Messages
2,001
Reaction score
1
If I have a function that takes a std::vector< T1 > and I pass it a std::vector< T2 >, where T2 is publicly derived from T1, that should work, why does my compiler complain?
 
Physics news on Phys.org
What makes you think that should work? A vector of references or pointers might work; note well that I am not saying it will. A vector of actual instances is a different beast. I would think that this should not work.
 
You have to pass a pointer to the vector, and make sure the vector elements are the same.