1

I'm trying to use constexpr in C++ but get the compile error: 'constexpr' was not declared in this scope.

I tried both in CodeBlocks using the GNU GCC compiler, and in Visual Studio 2013.

the code is:

#include <iostream>

int main()
{
    constexpr double ft2m = 0.3048;
    std::cout << ft2m;
}

What could be the problem?

4
  • Which version of GCC? Commented Mar 6, 2017 at 7:54
  • Also, partial duplicate here (regarding VS2013). Commented Mar 6, 2017 at 7:54
  • I'm going guess that you need to change your compiler settings so that it compiles against the C++11 standard. Commented Mar 6, 2017 at 7:55
  • I've "finished" the code snippet so it compiles. Commented Mar 6, 2017 at 8:01

2 Answers 2

2

What version of gcc are you using?

You might need at -std=c++11 to your command line

Sign up to request clarification or add additional context in comments.

Comments

2

The problem is that MSVC2013 does not support constexpr. It does not purport to implement the C++11 standard.

The first version that does is MSVC2015.

Your constexpr statement is grammatically correct C++11. Make sure you have a GCC version compliant with that standard.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.