1. 程式人生 > >Mr.J--C語言編譯錯誤C3861

Mr.J--C語言編譯錯誤C3861

 

識別符號: 找不到識別符號

即使使用自變數相關的查詢,編譯器也無法解析對識別符號的引用。

備註

若要修復此錯誤,比較使用識別符號到識別符號宣告的大小寫和拼寫。 驗證範圍解析運算子和名稱空間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,因為未定義識別符號。

C++複製

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

不在作用域的識別符號

下面的示例生成 C3861 因為識別符號僅在其定義,檔案作用域中可見,除非它在使用它的其他原始檔中宣告。

C++複製

// 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
}

C++複製

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

所需的 Namespace 限定

C + + 標準庫中的異常類需要std名稱空間。

C++複製

// 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 庫中刪除過時函式。

C++複製

// 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 和友元函式

下面的示例生成 C3767,因為編譯器無法使用的自變數依賴於查詢FriendFunc:

C++複製

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
}

若要修復此錯誤,宣告友元類作用域中的,並在名稱空間範圍中定義它:

C++複製

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

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

int main() {
   func();
}

對於我遇到的問題,就是函式的先定義再使用....(First)