Visual C++ Expression must have a constant value

后端 未结 2 1990
轮回少年
轮回少年 2021-01-21 02:45

Does anyone know why Visual Studio is the only compiler to giving me this error - Expression must have a constant value (referring to size).

#include 

        
2条回答
  •  春和景丽
    2021-01-21 03:06

    The reason this is only happening with VC++ is that VC++ is (apparently) the only compiler you've tried that conforms to the C++ standard in this respect.

    For some time, C has had a feature known as "variable length arrays", that would allow this. Some C++ compilers (especially gcc) also allow them in C++ (at least by default), even though the C++ standard prohibits them.

    If you want something that acts like an array, but also allows you to specify its size at runtime, you usually want an std::vector instead of an array.

提交回复
热议问题