編譯器錯誤 C3861

' identifier ': 找不到識別碼

即使使用引數相依查閱,編譯器也無法解析識別碼的參考。

備註

若要修正此錯誤,請將識別碼的使用 與大小寫和拼字的識別碼 宣告進行比較。 確認 已正確使用範圍解析運算子 和命名空間 using 指示 詞。 如果在標頭檔中宣告識別碼,請在參考識別碼之前確認標頭已包含。 如果識別碼是要在外部可見,請確定該識別碼已在使用該識別碼的任何原始程式檔中宣告。 也請檢查條件式編譯指示詞 不會排除 識別碼宣告或定義。

從 Visual Studio 2015 中的 C 執行時間程式庫移除過時函式的變更可能會導致 C3861。 若要解決此錯誤,請移除這些函式的參考,或將其取代為其安全替代方案,如果有的話。 如需詳細資訊,請參閱 過時的函式

如果從舊版編譯器移轉專案之後出現錯誤 C3861,您可能有與支援的 Windows 版本相關的問題。 Visual C++ 不再支援將 Windows 95、Windows 98、Windows ME、Windows NT 或 Windows 2000 當做目標。 WINVER如果您的 或 _WIN32_WINNT 宏已指派給其中一個 Windows 版本,您必須修改宏。 如需詳細資訊,請參閱 修改 WINVER_WIN32_WINNT

範例

未定義的識別項

下列範例會產生 C3861,因為未定義識別碼。

// C3861.cpp
void f2(){}
int main() {
   f();    // C3861
   f2();   // OK
}

不在範圍中的識別碼

下列範例會產生 C3861,因為識別碼只會顯示在其定義的檔案範圍中,除非它宣告在其他使用它的來源檔案中。

原始程式檔 C3861_a1.cpp

// C3861_a1.cpp
// Compile with: cl /EHsc /W4 C3861_a1.cpp C3861_a2.cpp
#include <iostream>
// Uncomment the following line to fix:
// int f();  // declaration makes external function visible
int main() {
   std::cout << f() << std::endl;    // C3861
}

原始程式檔 C3861_a2.cpp

// C3861_a2.cpp
int f() {  // declared and defined here
   return 42;
}

需要命名空間限定性

C++ 標準程式庫中的例外狀況類別需要 std 命名空間。

// C3861_b.cpp
// compile with: /EHsc
#include <iostream>
int main() {
   try {
      throw exception("Exception");   // C3861
      // try the following line instead
      // throw std::exception("Exception");
   }
   catch (...) {
      std::cout << "caught an exception" << std::endl;
   }
}

已呼叫的過時函式

已從 CRT 程式庫移除過時的函式。

// C3861_c.cpp
#include <stdio.h>
int main() {
   char line[21]; // room for 20 chars + '\0'
   gets( line );  // C3861
   // Use gets_s instead.
   printf( "The line entered was: %s\n", line );
}

ADL 和 friend 函式

下列範例會產生 C3767,因為編譯器無法使用 的 FriendFunc 引數相依查閱:

namespace N {
   class C {
      friend void FriendFunc() {}
      friend void AnotherFriendFunc(C* c) {}
   };
}

int main() {
   using namespace N;
   FriendFunc();   // C3861 error
   C* pC = new C();
   AnotherFriendFunc(pC);   // found via argument-dependent lookup
}

若要修正錯誤,請在類別範圍中宣告 friend,並在命名空間範圍中定義它:

class MyClass {
   int m_private;
   friend void func();
};

void func() {
   MyClass s;
   s.m_private = 0;
}

int main() {
   func();
}