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?

Bathsheba
  • 231,907
  • 34
  • 361
  • 483
J.tuc
  • 21
  • 2

2 Answers2

2

What version of gcc are you using?

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

qianfg
  • 878
  • 5
  • 8
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.

Bathsheba
  • 231,907
  • 34
  • 361
  • 483