Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

C++ question

  1. Jul 7, 2008 #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?
  2. jcsd
  3. Jul 7, 2008 #2

    D H

    User Avatar
    Staff Emeritus
    Science Advisor

    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.
  4. Jul 7, 2008 #3


    User Avatar
    Homework Helper

    You have to pass a pointer to the vector, and make sure the vector elements are the same.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook