如何快速识别功能从头文件? [英] How to quickly identify functions from header files?

查看:209
本文介绍了如何快速识别功能从头文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对C / C ++有点陌生,我发现自己花费了大量的时间搜索头文件(一个无辜的包可能会带来几十个头文件)。即使有用的IDE像Visual Studio也并不总是有用;有时当我尝试去定义一个函数时,它会提示我从几个选择 - 我试图避免的东西。



所以...在一个非常大的项目中有成千上万的头文件和许多共享相同名称和参数的函数,什么是最好的方式来确定,哪个特定的函数被调用?

这将输出给定.cpp文件编译中使用的所有标头。这不是一个快速的方法,但它是一种确定的方式。



当Intellisense不工作时,我建议在文件中查找。这样更容易跟踪标题中的定义。我发现我通常可以知道相关的声明。



请记住,你不能在标题中找到源,除非你处理模板或内联函数。因此,通常没有理由试图区分哪些声明正在被应用。如果定义存在于SOURCE文件(.c,.cpp)中,那么只有该名称和签名的一个函数可以编译。通常最好是谷歌的函数名称,如果它是从Microsoft或其他来源的已发布的API。



Visual Assist for Visual Studio等工具提高了定位的能力定义,以及。
此外,你可以按摩Intellisense变得更好。尝试删除Intellisense数据库并重建它。您可以通过它在错误视图中显示的错误了解它有什么问题。通常你需要改进includes目录,特别是如果这是一个makefile项目。如果它灰化的代码不应该是灰色的,一些预处理器符号是错误的。保持Intellisense通常是值得的,因为它工作时很好。



Visual Assist for Visual Studio之类的工具有自己的,经常改进的类似intellisense的方法来寻找定义。


I'm somewhat new to C/C++, and I find myself spending exorbitant amounts of time searching through header files (one innocent include might actually bring dozens more header files with it). Even helpful IDEs like Visual Studio aren't always helpful; sometimes when I try to go to the definition of a function, it prompts me to choose from several--the very thing I was trying to avoid.

So...in a very large project with thousands of header files and many occurrences of functions that share the same name and parameters, what's the best way to determine, without question, which specific function is being called?

解决方案

Try adding /showIncludes to the compiler command line (In the project settings, Configuration Properties, C/C++, Command Line). This outputs all the headers used in a given .cpp file compilation. This is not a fast way, but it is a sure way.

When Intellisense isn't working, I recommend Find in Files. It is easier to track down the definition in the header this way. I find I can usually tell which is the relevant declaration.

Keep in mind that you cannot find the source in the header, unless you are dealing with templates or inlined functions. So there is generally no reason to attempt to discriminate which declaration(s) are being applied. If the definition exists in a SOURCE file (.c,.cpp), then there can only be one function of that name and signature for it to compile. It is generally better to google the function name if it is a published API from Microsoft or another source.

Tools such as Visual Assist for Visual Studio improve the ability to locate such definitions, as well. Also, you can massage Intellisense into working better. Try deleting the Intellisense Database and having it be rebuilt. You can see where it has trouble by the "errors" it shows in the error view. Often you need to improve the includes directories, especially if this is a makefile project. If it grays out code that shouldn't be grayed out, some preprocessor symbol is wrong. Maintaining the Intellisense is often worth it because it's great when it works.

Tools such as Visual Assist for Visual Studio have their own, often improved intellisense-like method of finding definitions.

这篇关于如何快速识别功能从头文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆