共用方式為


連結器工具錯誤 LNK2020

未解析的令牌 'token'

類似於未定義的外部錯誤,不同之處在於參考是透過元數據。 在元數據中,必須定義所有函式和數據。

解決方式:

  • 定義遺漏的函式或數據,或

  • 包含已定義遺漏函式或數據的物件檔案或連結庫。

範例

下列範例會產生LNK2020。

// LNK2020.cpp
// compile with: /clr /LD
ref struct A {
   A(int x);   // LNK2020
   static int f();   // LNK2020
};

// OK
ref struct B {
   B(int x) {}
   static int f() { return 0; }
};

如果您建立Managed樣本類型的變數,但不會同時具現化類型,也會發生LNK2020。

下列範例會產生LNK2020。

// LNK2020_b.cpp
// compile with: /clr

template <typename T>
ref struct Base {
   virtual void f1() {};
};

template <typename T>
ref struct Base2 {
   virtual void f1() {};
};

int main() {
   Base<int>^ p;   // LNK2020
   Base2<int>^ p2 = gcnew Base2<int>();   // OK
};