-
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
-
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.
-
You should also accept the vector by reference:
Code:
void load(std::vector<string> &maze)
-
And as it seems to be readonly, make it a const reference.