0

I'm trying to use constexpr for the first time in C++ on Mac. I am using sublime text but am compiling through terminal. Here is the command I'm using to compile: g++ -o helloworld helloworld.cpp Let me make something clear: I KNOW THIS QUESTION IS A DUPLICATE, but all the other questions were using xCode or VS Code, and since I'm using a text editor, not an IDE, then those answers don't apply to me. I know that people will ask for this, so here is what happens when I run the following command:

g++ --version
//...
Apple clang version 11.0.3 (clang-1103.0.32.29)
Target: x86_64-apple-darwin19.4.0
Thread model: posix

Here is the code:

#include <iostream>

constexpr int cube(int n){
    return n*n*n;
}

int main(){

    constexpr int hello = 2*cube(5);
    auto niceNum = 69.420;
    std::cout << hello << niceNum << "\n";

}

Here is the output:

helloworld.cpp:3:1: error: unknown type name 'constexpr'
constexpr int cube(int n){
^
helloworld.cpp:9:2: error: unknown type name 'constexpr'
        constexpr int hello = 2*cube(5);
        ^
helloworld.cpp:10:2: warning: 'auto' type specifier is a C++11 extension
      [-Wc++11-extensions]
        auto niceNum = 69.420;
        ^

(There is also an error with the auto keyword, which I'm assuming is related to the constexpr issue, since they're both unique to C++, meaning they're not included in C) Thanks.

Serket
  • 3,785
  • 3
  • 14
  • 45

0 Answers0