I am trying to create class with lazy calculations. So I need struct to hold previously calculated variables and I want to put that class into unnamed namespace(don't want to pollute global scope). Here is minimal code which explains what I want:
calculator.h
:
#ifndef CALCULATOR_H
#define CALCULATOR_H
class PrevCalc;
class Calculator
{
public:
Calculator();
PrevCalc* prevCalc;
};
#endif // CALCULATOR_H
calculator.cpp
:
#include "calculator.h"
namespace{
struct PrevCalc{
double prevA = -1;
double prevB = -1;
double prevC = -1;
};
}
Calculator::Calculator()
{
prevCalc = new PrevCalc();
}
Of course it gives an error expected type-specifier before 'PrevCalc'
and if I define PrevCalc
without namespace everything works fine. My question is how to declare class which will be defined in unnamed namespace in .cpp
file