Tuesday, June 08, 2010

Visual Studio 2008 IntelliSense Tips

Recently started working with Visual Studio 2008 again. Unfortunately my current project is restricted to 2008 and we can't yet upgrade to Visual Studio 2010.

Visual Studio 2008's C++ IntelliSense is a big improvement over Visual Studio 2005, however at times I find it still has difficulties showing popup info and going to definition. If you search for these types of problems you find many people advising deleting *.ncb and rebuilding. After some trial and errors and hints from Microsoft sites about potential parser problems, I can offer the following advice which has worked great for me for solving these types of issues.

If the "Go To Definition" goes to the declaration instead of the method definition, then make sure the declaration does not use any immediately undeclared types. By immediate I mean in the header file itself. Pre-compiled headers do not seem to count.

For example:

void foo(const string& str, ostream& os);
// should be:
void foo(const std::string& str, std::ostream& os);

// make sure A is forward declared, or included
void foo(const A& a);

// make sure Temp and A are forward declared,
// class A;
// template <class X> class Temp;
void foo(Temp<A>& t);