Problem with a function
Hi everybody! I try to create same little function with 2d vector as argument to it, but my compiler gives ununderstandable error for me. Can somebody help?
My compiler gives me a mistake in line 20, it says:
error: expected ',' or '...' before '(' token
Here is a code:
#define ROW 8
#define COL 8
using namespace std;
void fillVect(vector<vector<int> >&);
vector<vector<int> > myVec(ROW,vector<int>(COL));
void fillVect(vector<vector<int> > &vect(ROW,vector<int>(COL)))
Line 20 should be:
void fillVect(vector<vector<int> > &vect)
As I understand I shouldn't declare all sizes of vector. The compiler does it by itself. Thanks to this operator &. Am I right?
Your line was just syntaxically incorrect. Argument should contain: variable type (
vector<vector<int>>& in your case) and local variable name (
vect in your case)
It may be a misunderstanding of the meaning of line 13, which led to confusion later on.
We can declare a vector like this:
and a 2-D vector like this:
vector<vector<int> > b;
What line 13 is doing is calling the constructor to build the new vector. That's not part of the declaration, and it doesn't make sense to put the constructor in the function definition.
Thanks guys for all. I understood.
Topic archived. No new replies allowed.