3

GCC で以前のビルドと同じように機能した C++ ファイルをコンパイルするときに、いくつかの問題が発生しています。問題は、可変配列サイズのベクトルを使用していることです。

unsigned int howmany;
std::vector<int>* array_adresses[howmany]; 

現在、Visual-Studio 2010 C++ コンパイラを使用して、Matlab 64 ビット Mex ファイルをビルドしています。VC++ ではコンパイル時にサイズが不明な配列を使用できないため、次のエラー メッセージが表示されます。

エラー 2057: 定数式が必要です エラー 2466: エラー 2133: 不明なサイズ

GCC コンパイラ オプションを使用して 64 ビット mex ファイルをビルドする方法や、Matlab で別の 64 ビット コンパイラを使用してビルドする方法はありますか?

前もって感謝します!!

4

3 に答える 3

4

howman は定数である必要があり、次のように定義された量である必要があります。

const unsigned int howmany = 5;
std::vector<int>* array_adresses[howmany];

または、次のように動的に定義できます。

unsigned int howmany = 5;
std::vector<int>* array_adresses = new std::vector<int>[howmany];
于 2011-04-04T09:13:01.057 に答える
2

C++ standard doesn't allow variable-length arrays. Lets take this code:

int main(int argc, char *argv[])
{
    int a[argc];
    return 0;
}

This compiles fine with g++ foo.cpp, but fails if you require a strict standard compliance.

g++ foo.cpp -std=c++98 -pedantic:

foo.cpp: In function ‘int main(int, char**)’:
foo.cpp:8: warning: ISO C++ forbids variable length array ‘a’

You should use vector<vector<int> *> or vector<int> ** instead as others already suggested.

于 2011-04-04T09:54:44.980 に答える