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) 

猜你喜欢

转载自blog.csdn.net/Ms_yjk/article/details/83097092
今日推荐