Mapping a Visual C++ filter to a physical folder

There is one annoyance in Visual C++ (2010/2012) for people used to C#’s solution/project folder behavior where a folder in the project maps to a namespace, and any files/classes you add to that folder are physically added to an equivalent subfolder in the file system. Unfortunately, with VC++, the closest equivalent is a project filter which is not a physical folder. There are some very obvious disadvantages to this approach.

  • You cannot have the same filename under multiple filters. Example, if you have base.h under the data filter and you want to add base.h to the view filter, you cannot, since they are both in the root folder.
  • A second issue is that when you #include files, you cannot use the filter name in the path, and have to use the physical path which may often be confusing.
  • File organization also gets messy because all the files get created in one single folder.

A workaround that I use is to do this.

  • I create a physical sub-folder inside the project folder.
  • I then select “show all files” in the solution explorer and manually include this folder
  • Then, I create a filter of the same name (as the subfolder)
  • I then add new files/classes to this folder, and also drag/drop the file into the filter in solution explorer

Obviously, this is a bit of a hassle, but it’s still the simplest approach given the way they chose to make filters work. You can save one step by selecting the right folder when adding a file/class to a filter.


I hope the next version of VC++ will emulate the more intuitive and convenient behavior available for C# projects.


3 thoughts on “Mapping a Visual C++ filter to a physical folder

    1. I’ve not had an issue yet. I just tried again to be sure. Added a filter/folder called Test, added a source.cpp there with one single line : #include “stdafx.h” and did a re-build. Compiled fine. VC++ 2012 here.

    2. I suspect you are talking about the intellisense squiggle. If so, yeah I get it too. It does compile fine though. The compiler knows how to specially handle the pch file but intellisense probably needs it to be specified in the additional includes list.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s