Passing Vector<string>

This is a discussion on Passing Vector<string> within the C++ Programming forums, part of the General Programming Boards category; How do I get this to work? I have a Vector<string> maze; which is passed on to this function: Code: ...

  1. #1
    Registered User
    Join Date
    Sep 2010
    Posts
    10

    Passing Vector<string>

    How do I get this to work?

    I have a Vector<string> maze; which is passed on to this function:

    Code:
    void load( Vector<string> maze)
    {
        height_ = maze.size();
        if(height_ == 0) return;
        width_ = maze.get(0).length();  
        if( width_ == 0 ) return;
        
        maze_= new int[height_][width_];
        for(int i=0; i < height_; i++)
    
        {
    
            for( int j=0 ; j < width_ ; j++ )
    
            {
    
                maze_[i][j] = maze.get(i).charAt(j) - '0';
    
            }
    
        }
    }

    but my compiler says:

    maze.cpp:287: error: variable or field ‘load’ declared void
    maze.cpp:287: error: ‘Vector’ was not declared in this scope
    maze.cpp:287: error: expected primary-expression before ‘>’ token
    maze.cpp:287: error: ‘maze’ was not declared in this scope

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,317
    What is "Vector"? The standard library class that works like an array is called "vector" with a lower-case 'v'. Case matters in C++. If that's what you're using also make sure you #include<vector> and #include <string>.

    If Vector is different from std::vector, then make sure you #include the header file that declares that class.
    Last edited by Daved; 10-11-2010 at 02:32 PM.

  3. #3
    a_capitalist_story
    Join Date
    Dec 2007
    Posts
    2,639
    You should also accept the vector by reference:
    Code:
    void load(std::vector<string> &maze)

  4. #4
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138
    And as it seems to be readonly, make it a const reference.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Passing Argument from incompatible pointer type
    By AmritxD in forum C Programming
    Replies: 3
    Last Post: 08-15-2010, 03:23 PM
  2. passing argument from incompatible pointer type
    By bhdavis1978 in forum C Programming
    Replies: 5
    Last Post: 03-17-2010, 12:42 PM
  3. Passing Arguments
    By bolivartech in forum C Programming
    Replies: 13
    Last Post: 10-15-2009, 01:31 PM
  4. Newb Question on Passing Objects as Parameters
    By Mariano L Gappa in forum C++ Programming
    Replies: 12
    Last Post: 11-29-2006, 12:08 PM
  5. Passing by reference not always the best
    By franziss in forum C++ Programming
    Replies: 3
    Last Post: 10-26-2005, 07:08 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21