Title: g++ compiler error when calling function(vector <vector<int> > &)
Tags: c++;pass-by-reference;stdvector
Question: Can anyone tell me why this simple function call returns the compiler error shown at bottom?

```//This is a type definition that I use below to simplify variable declaration
typedef vector<int&gt; islice;
typedef vector<islice&gt; int2D;
// therefore int2D is of type  vector<vector<int&gt; &gt;

// This is the function prototype in the DFMS_process_spectra_Class.hh file
int DumpL2toFile(int2D&amp;);

// This is the type declaration in the caller
int2D L2Data;

// This is the function call where error is indicated
int DumpL2toFile(L2Data);      (**line 90 - error indicated here**)

// this is the function body 
int DFMS_process_spectra_Class181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16umpL2toFile(int2D&amp; L2) {

    string file=sL3Path+L2Info.fileName;
    fstream os;
    os.open(file.c_str(), fstream181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16out);
    os << "Pixel   A-counts   B-counts" << endl;
    char tmp[80];
    for (int i=0; i<512; ++i) {
        sprintf(tmp,"%5d    %8d    %8d\n",L2[i][0],L2[i][1],L2[i][2]);
        os << string(tmp) << endl;
    }

    os.close();

    return 1;
}
```

//This is the compiler command and error

```g++ -w -g -c src/DFMS_process_spectra_Class.cc -o obj/DFMS_process_spectra_Class.o
src/DFMS_process_spectra_Class.cc: 
In member function 'int   DFMS_process_spectra_Class181a:6c1c:918f:f3a4:2e8c:61d6:1a08:6b16processL2()':
 src/DFMS_process_spectra_Class.cc:90: error: 
                      cannot convert 'int2D' to 'int' in initialization
```

Why is the compiler confusing ```int2D&amp;``` with ```int```?  The call, function prototype, and function are consistently ```int2D``` type!!

//Here is my compiler version
    i686-apple-darwin11-llvm-g++-4.2  on Mac OS X 10.8.3

This by the way is the same error I get on my Linux box with g++ 4.3

Thanks for any help,  Mike



Here is another answer: ```// This is the function call where error is indicated
int DumpL2toFile(L2Data);      (**line 90 - error indicated here**)
```

That's not a function call! Assuming that this line occurs inside a function body (which is not clear from your code), the function call would be:

```DumpL2toFile(L2Data); // No int
```

OP, that's all you need to know. But if you are curious, the compiler is parsing your statement as if it were

```int AnyOldIdentifier(L2Data);
```

which is a declaration of an ```int``` variable called ```AnyOldIdentifier```, initialised to the value ```L2Data```. And it can't initialise an ```int``` to ```L2Data```, because ```L2Data``` is an ```int2D```, not an ```int```.

Comment for this answer: Thanks all!!  I actually figured it out on my own.  Just a dumb cut and paste problem.  I cerated the function prototype, cut and pasted it into the class body and didn't complete the edit!!  Sorry for wasting your time.   Stupid is as stupid does sometimes.

Here is another answer: You have syntax error around this line:

```   // This is the function call where error is indicated
  int DumpL2toFile(L2Data);      (**line 90 - error indicated here**)
```

If you call ```DumpL2toFile```. you don't need the return type anymore. this way, compiler treats it as function declaration, however, ```L2Data``` is not a type, it is an object of ```int2D```, this triggers compiling error

Meanwhile, compile error says error insde ```processL2()``` function, while you did not post code of this part.

Comment for this answer: I guess bumping my head while Easter egg hunting with my nieces didn't help :-)
Comment for this answer: Actually I have a different question.  Why didn't the compiler complain that this was a shadow declaration?  After all I had already declared  the function in the .h file.  Shouldn't the compiler complain about shadow methods like it does about shadow variables?

{'source': 'StackExchangeDataset', 'subset': 'stackoverflow.com', 'metadata': {'AnswerCount': 2, 'CommentCount': 0, 'ContentLicense': 'CC BY-SA 3.0', 'CreationDate': '2013:00:03/31/13', 'FavoriteCount': None, 'PostTypeId': 1, 'Tags': '<c++><pass-by-reference><stdvector>', 'Title': 'g++ compiler error when calling function(vector <vector<int> > &)', 'ViewCount': 161, 'id': 15733907, 'user_AboutMe': '<p>Physical scientist who is always dabbling with a new computer language!</p>\n', 'user_AccountId': 2571418.0, 'user_DisplayName': 'MikRin', 'user_Reputation': 3.0, 'user_Views': 2.0, 'user_id': 2230049.0}}