myMain.cpp:
#include <memory>
#include "myClass.h"
static std::unique_ptr<myClass> classPtr; // Error thrown here
...
I am initializing in global scope because loading all the data into the properties of this class takes a while, so I'd like to do it once and have that data persist until I give an explicit command to delete it (classPtr.reset(nullptr)).
When I try to compile this: g++ myMain.cpp -o myMain.o I get: error: expected initializer before '<' token.
Why am I getting this error?
I've defined myClass in myClass.h and myClass.cpp; I think the error has to do with the constructor. I've simplified code & included only the important lines below.
myClass.h:
class myClass {
std::string dataPath;
std::vector<double> data;
public:
myClass(std::string P = "./path/to/data-file.csv");
~myClass() {}
const double findPercentile(double percentile = 0.0);
}
EDIT: Following tip from @FrançoisAndrieux I have fixed my constructor.
myClass.cpp:
myClass::myClass(const std::string P) :
dataPath(P) {
// read data-sets into class member variables
}
myClass(std::string)but implement it asmyClass(const std::string). You define the argument to have the default value"./path/to/data-file.csv"but then you disregard the argument and always initialize with the default value.