c++visual-studio-2010matlabmex

Error with variable array size using the visual C++ compiler (Visual Studio 2010). How to circumvent this issue?


I am experiencing some troubles compiling a c++ file that worked well as a previous build under GCC. The issue is, I am using vectors of variable array size:

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

I am currently using the Visual-Studio 2010 C++ compiler to built Matlab 64-bit Mex-Files. Since VC++ won't allow me to use arrays whose size is unknown at compile time, I am receiving the following error messages:

error 2057: constant expression expected error 2466: error 2133: unknown size

Is there any way to build the 64 bit mex file using a GCC-compiler option or build it with a different 64-bit compiler under Matlab?

Thanks in advance!!


Solution

  • howmany needs to be constant, and needs to be a defined amount, like so:

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

    Or you can define it dynamically like this:

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