I have Commons.h
file that contains "general" structures and classes declarations. Among others it contains such class declaration (only static int nInstrument
is important, you can ignore the rest):
class Instrument
{
public:
int Id() {
return _id;
}
int GateId() {
return _gateId;
}
const std::string& const ClassCode() const {
return _classCode;
}
const std::string& const Ticker() const {
return _ticker;
}
Instrument(int gateId_, std::string classCode_, std::string ticker_)
{
_gateId = gateId_;
_classCode = classCode_;
_ticker = ticker_;
_id = nInstrument;
std::cout << "New Instrument created << " << _ticker << " id = " << _id << std::endl;
++nInstrument;
}
private:
static int nInstrument;
int _id;
int _gateId;
std::string _classCode;
std::string _ticker;
};
I need to initialize static int nInstrument;
with 0
. It's easy If I have Commons.cpp
file as answered in this question. But I don't ave Commons.cpp
file and I don't want to create it just to put one line int Instrument::nInstrument = 0;
I want to double check that C++11
or future standart still doesn't have such feature? So I have to add cpp
just to put one initialization line?