Variable length array of non-POD element type 'string' (aka 'basic_string') c++

后端 未结 3 2031
傲寒
傲寒 2021-01-07 10:16

I get this error in my c++ code Variable length array of non-POD element type string (aka basic_string).

string words[n         


        
3条回答
  •  星月不相逢
    2021-01-07 11:01

    C++ doesn't have C99-style variable length arrays. Your compiler might support them as an extension, but they're not part of the language. In this specific case, your success with Visual Studio indicates that it does in fact have such an extension. clang++ will support VLAs, but only of POD types, so your attempt to make a VLA of string objects won't work. g++ does work on my machine if I leave off enough warning/error flags.

提交回复
热议问题