0

この単純な関数呼び出しが、下部に示されているコンパイラ エラーを返す理由を誰か教えてもらえますか?

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

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

// 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_Class::DumpL2toFile(int2D& L2) {

    string file=sL3Path+L2Info.fileName;
    fstream os;
    os.open(file.c_str(), fstream::out);
    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;
}

//これはコンパイラのコマンドとエラーです

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_Class::processL2()':
 src/DFMS_process_spectra_Class.cc:90: error: 
                      cannot convert 'int2D' to 'int' in initialization

コンパイラが と混同int2D&するのはなぜintですか? 呼び出し、関数プロトタイプ、および関数は一貫してint2D型です!!

//これは、Mac OS X 10.8.3 上の私のコンパイラ バージョン i686-apple-darwin11-llvm-g++-4.2 です。

ちなみに、これは Linux ボックスで g++ 4.3 を使用した場合と同じエラーです。

助けてくれてありがとう、マイク

4

2 に答える 2

0

この行の周りに構文エラーがあります:

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

あなたが呼び出す場合DumpL2toFile。戻り値の型はもう必要ありません。このように、コンパイラはそれを関数宣言として扱いますがL2Data、型ではなく、のオブジェクトですint2D。これにより、コンパイル エラーが発生します。

その間、コンパイルエラーはエラーinsdeprocessL2()関数を言いますが、この部分のコードを投稿しませんでした。

于 2013-03-31T20:10:15.860 に答える