Pregunta

I have this .h file:

namespace{

class Invariant{
public:
  Invariant(z3::expr e,Instruction *i):Expr(e),I(i){
    DenseMap<Instruction*,Invariant*> FunMap = Invariants[F];
  }

private:
  //static map
  static DenseMap<Function*, DenseMap<Instruction*,Invariant*> >Invariants;

};
}//end of anonymous namespace

When I compile clang says:

Invariant.h:46:65: warning: variable '<anonymous namespace>::Invariant::Invariants' has internal linkage but is not defined
  static DenseMap<Function*, DenseMap<Instruction*,Invariant*> >Invariants;
                                                                ^
Invariant.h:26:48: note: used here
    DenseMap<Instruction*,Invariant*> FunMap = Invariants[F];

What's the problem here?

¿Fue útil?

Solución

Just define it. After the class definition but before the end of the anonymous namespace add this line:

DenseMap<Function*, DenseMap<Instruction*,Invariant*> > Invariant::Invariants;

This will create the static member in every translation unit that includes this header (that's okay because it's in the anonymous namespace, which is unique to each translation unit). That's probably not what you want, but that follows from defining Invariant in an anonymous namespace. If you use a named namespace instead, you can put the definition of Invariants into a source file and have only one object shared by all the code.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top