0

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?

stenrap
  • 39
  • 1
  • 6
  • 1
    I think it all depends on the libraries and IDE you're using. For instance, I use the Qt library with Qt Creator exclusively and I've never had a problem looking anything up. The headers (and source) are there if I need them but the documentation is top-notch so I never find myself going through any header files (except for my own). –  Oct 07 '11 at 03:29
  • Functions cannot have the same name and the same parameters. Anyway, what functions are you having trouble finding? In general, Visual Studio gives me a short list where any of the functions will take me close enough to the definition that I can find the actual implementation of the function. Failing that, you can always put a breakpoint on the line and then step into it. That's guaranteed to take you to the right place! – Ayjay Oct 07 '11 at 03:47
  • @Ayjay: Functions could have the same name if its C++. And *might* even be a good idea (overloading the + operator for instance). However, you should know what class your dealing with and be able to search on that. – whitey04 Oct 07 '11 at 03:55
  • 1
    @whitey04: Sorry, I guess I meant within the same namespace they can't - you can't have the same name AND parameters within the same namespace, otherwise the compiler doesn't know which function to call. Within a given project, though, you can have many namespaces which means you could potentially have multiple functions with the same name and same parameters. I don't know if I've ever seen that, but I guess it's possible. – Ayjay Oct 07 '11 at 04:31

4 Answers4

1

Admittedly, I'm still new to C++ (and programming in general) as well. But, I think that the Visual Studio feature you describe in your question is the most help you'll get. It will narrow things down a little for you, but you'll still have to do some good ole sleuthing.

jwfriese
  • 228
  • 2
  • 9
1

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.

VoidStar
  • 5,241
  • 1
  • 31
  • 45
0

Ask the compiler. No, really! It's the only way to be sure.

SamB
  • 9,039
  • 5
  • 49
  • 56
0

Try using Microsoft visual studio 2005. You can easily jump onto the function definition, Function declaration also you can see the Function call and callers graph as well.

Yogi
  • 83
  • 1
  • 10