编译以下源时:
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/