const correctness and vectors

Discussion in 'C++' started by PhilRosenberg, Oct 5, 2010.

  1. PhilRosenberg

    PhilRosenberg New Member

    Joined:
    Oct 5, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    Hi all.
    I'm passing a number of large vectors of doubles to a class. I don't know the number of vectors that will be needed at compile time and I want to avoid creating multiple copies of the vectors. Hence I'm passing them as a vector of pointers to vectors of doubles, i.e.
    void myfunc(vector< vector < double >* > passed_arrays);

    I only use the data from the vectors and do not change them so I want to make this const correct.

    I've tried
    myfunc(vector< const vector * > passed_array);
    but then if the user passes a non-const vector I get errors abount cannot convert from std::vector to const std::vector.

    Any ideas where I need to put my const(s)?
     
  2. techgeek.in

    techgeek.in New Member

    Joined:
    Dec 20, 2009
    Messages:
    572
    Likes Received:
    19
    Trophy Points:
    0
    Occupation:
    EOC (exploitation of computers)..i m a Terminator.
    Location:
    Not an alien!! for sure
    Home Page:
    http://www.techgeek.in
    Make the vector constant use the following method:-
    Code:
     
    
    myfunc(vector< const vector * > const passed_array); 
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice