For the last eight years I wait for Microsoft to add the basic C++ functionality of switching back and forth between .h and .cpp files, and it keeps astonishing me it is still not supported in Visual Studio 2010. Does anyone know why they refuse to add this essential feature?
Visual Assist does it, but also offers you to open any file in your solution which has a name that includes the substrings you give. Extremely useful in my opinion: I always use it, but very hardly use the 'jump to header/source' command...
It's easy to write a macro that does it: Switch between Header and CPP File for Visual Studio .NET by Pavel Sokolov, Pierre Arnaud
Pavel Sokolov's Solution
A simple macro that allows you to quickly switch between the associated header and implementation files. This is a modification for Visual Studio .NET of the macro by Nooruddin Kapasi.
This macro simply switches between a
*.hfile and a
*.cppfile, without any errors (if the
*.cppfile does not exist)...
Pierre Arnaud's Solution
Switch_H_CPPmacro switches between the active document (either source file or header file) and its counterpart (either header file or source file). Whereas simpler macros get this job done more efficiently (see the above), they do not work if the header files and source files are not stored in the same directory...
Switch_H_CPPlooks for a matching counterpart by walking through all the loaded project files. It can, therefore, deduce the full path of the file and open it even if it is in a different directory as the active document...
I've not used Visual Studio for a few years, but IIRC the "Go To Definition" and "Go To Declaration" functions do this (albeit badly, particularly when it comes to constructors)
I imagine that one reason for them not implementing it on a filename basis is that there is nothing about C++ that enforces a convention on the arrangement of classes in files.
e.g. The "obvious" way to arrange a class called "MyClass" in a C++ project is to put the class in MyClass.h and the methods in MyClass.cpp.
Another, totally plausible way is to put the class definition in "elephant.h" and the methods in "mouse.cpp"
You could put all of your classes in one "classes.h" file and define all of your methods in one method per file.
I'm not saying that you should arrange your projects in this way, just that you could, and that's why jumping between .cpp and .h files is implausible, unless done in the same manner in which it is already implemented.
As discussions on Visual Assist shows, this feature is far from simple: which extensions are included (.c, .cpp, .cxx, .h, .hpp, .nothingatall, .inl, ...), which way you cycle through them when there are more than two, etc.
I agree it's still a rather simple feature to implement, but it's not as simple as you think.