c++ - 如果在其库未直接包含在源代码中时使用标识符,是否可以强制 Visual Studio 抛出错误?

标签 c++ visual-studio-2010 include

编译以下源时:

int main()
{
  exp(1.0);

  return 0;
}

编译器给出以下错误:error C3861: 'exp': identifier not found因为我没有这条线:#include <iostream>以上main()

但是,如果间接包含库,visual studio 将不会显示错误。例如,即使 exp 的依赖项,以下代码编译也没有问题在<cmath> .

#include <istream>
int main()
{
  exp(1.0);

  return 0;
}

这是因为 <iostream>包括 <istream>其中包括<ostream>其中包括<ios>其中包括<xlocnum>其中包括<cmath> .

如果我没有明确包含一个库但尝试使用它的标识符之一,有没有办法让 Visual Studio 抛出错误?

最佳答案

您可能想看看 include-what-you-use .这是一个 clang - 基于工具,试图检测丢失和多余的包含指令。

关于c++ - 如果在其库未直接包含在源代码中时使用标识符,是否可以强制 Visual Studio 抛出错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13828464/

相关文章:

android - 使用数据绑定(bind)将数据传递给 <include> 布局

c++ - 如何清除 XFixes 区域

c++ - 以下程序中的段错误

c++ - 为 C++ 类生成 set/get 方法

visual-studio-2010 - 在 Visual Studio 中创建源文件的物理副本

visual-studio-2010 - Visual Studio Windows 模拟器无法运行。给出 "The interface is unknown"错误

php - 数据库连接不作为包含文件工作

c++ - 强制 String to int 函数消耗整个字符串

visual-studio-2010 - Visual Studio以 'Release'模式运行项目,但不以 'Debug'模式运行

c++ - CMake target_include_directories(系统...): SYSTEM option does not seem to work on recent versions of CMake targeting Xcode