簡體   English   中英

如果在其庫未直接包含在源中時使用標識符,是否可以迫使視覺工作室拋出錯誤?

[英]Is it possible to force visual studios to throw an error if an identifiers is used when its library isn't directly included in the source?

編譯以下源代碼時:

int main()
{
  exp(1.0);

  return 0;
}

編譯器給出以下錯誤: error C3861: 'exp': identifier not found因為我沒有一行: main()上方的#include <iostream>

但是,如果間接包含一個庫,視覺工作室將不會顯示該錯誤。 例如,即使exp的依賴項位於<cmath> ,下面的代碼也可以毫無問題地進行編譯。

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

  return 0;
}

這是因為<iostream>包括<istream> ,其中<ostream>包括<ios>包括<xlocnum>包括<cmath>

如果我沒有明確包含庫但嘗試使用其標識符之一,是否可以使視覺工作室拋出錯誤?

您可能想看看include-what-you-use 這是一個基於clang的工具,試圖檢測丟失和多余的include指令。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM