I am trying to compile the below program. However it's giving me the error: unknown type name 'constexpr' error. What should I do?
Code:
//this is model.cpp. battery.cpp and load.cpp are two secondary files
#include "load.h"
#include "battery.h"
//compile time constants - Settings
constexpr int intervals = 96;
constexpr float e_min = 0.001;
constexpr int max_iters = 100;
constexpr int nloads = 10;
constexpr int nbat = 10;
struct devices
{
load loadDevices[nloads];
battery batteryDevices[nbat];
};
int main()
{
//Initialization of the model
devices devices1;
return 0;
}
I get the same error on each line where constexpr is used.
error: unknown type name 'constexpr'
constexpr int intervals = 96;
My C/C++ configurations .json file is as follows:
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [],
"compilerPath": "/usr/local/bin/gcc-11",
"cStandard": "gnu17",
"cppStandard": "gnu++17",
"intelliSenseMode": "macos-gcc-x64"
}
],
"version": 4
}
System: MACOSX
IDE: VSCode
Compiling on Mac's Terminal using g++
compilation command: g++ model.cpp battery.cpp load.cpp
-std=c++11/14/17/20 ?g++ -std=c++11 model.cpp battery.cpp load.cppin the mac terminal to compile?Undefined symbols for architecture x86_64:error for the method"optAlg::bufferPlanning(float*, float, float, int, float*, float*, float, float, float*, float*, bool, float*, int, float*, float*)", referenced from: battery::plan(float*) in battery-011c04.o