user7238425
user7238425

Reputation: 3

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.

Upvotes: 0

Views: 554

Answers (1)

Ben Voigt
Ben Voigt

Reputation: 283733

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.

Upvotes: 3

Related Questions