I am trying to create a class with lazy calculations. Therefore, I need a structure for storing previously calculated variables, and I want to put this class in an unnamed namespace (I don't want to pollute the global area). Here is the minimal code that explains what I want: calculator.h :
#ifndef CALCULATOR_H #define CALCULATOR_H class PrevCalc; class Calculator { public: Calculator(); PrevCalc* prevCalc; }; #endif
calculator.cpp :
#include "calculator.h" namespace{ struct PrevCalc{ double prevA = -1; double prevB = -1; double prevC = -1; }; } Calculator::Calculator() { prevCalc = new PrevCalc(); }
Of course, this gives the expected type-specifier before 'PrevCalc' , and if I define PrevCalc without a namespace, everything works fine. My question is how to declare a class to be defined in an unnamed namespace in a .cpp file
c ++
Leo
source share