10

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?

4

1 に答える 1

8

定義するだけです。クラス定義の後、匿名名前空間の終了前に、次の行を追加します。

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

これにより、このヘッダーを含むすべての翻訳単位に静的メンバーが作成されます (各翻訳単位に固有の匿名名前空間にあるため、問題ありません)。Invariantそれはおそらくあなたが望むものではありませんが、匿名の名前空間で定義することから生じます。代わりに名前付きネームスペースを使用すると、 の定義をInvariantsソース ファイルに入れ、すべてのコードで 1 つのオブジェクトだけを共有することができます。

于 2013-04-08T14:28:30.990 に答える