简体   繁体   中英

Enable c++14 in visual studio 2015 cmake

I am trying to have a dynamically sized array on the stack. I have the following code

int length = 0;
getLength(&someVar, &length);

char infoLog[length];

but I can't do it. I originally developed the code on macOS and had no problem compiling it. I did some research and found out c++14 supports this, but I am not sure how to turn it on in CMake (or in VS2015 community edition).

Thanks

EDIT: As drescherjm showed it wasn't actually added to the spec. Did it as per the answer below.

No, C++14 does not support it.

Try using a dynamic container instead:

std::vector<char> infoLog(length);

If you don't want to allow resizing after creation (because the VLA doesn't), then

auto infoLog = std::make_unique<char[]>(length);

Both will use heap space to store the content, and free it automatically when the variable infoLog leaves scope.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM