How to hide private members of a Class?

This might not be the best answer nor is it a pretty answer but it get's the job done and if you can live with a small syntax change then it will definitely work. One trick that I learned from observing std classes such as std::vector is that they denote private members with the prefix _, thus forcing all the private members to the very bottom of intellisense. It doesn't remove them from the list but it will move them all to the very bottom so they don't bother you when you are scrolling the list. Here's an example:

class SomeClass{
public:
   int myPublicMemeber;
private:
   int _myPrivateMember;
};

You can use regions, like this:

class MyClass {

    #region Private Variables

    private int x;
    private int y;
    private int z;

    #endregion

}

Visual Studio will display a little - next to the #region line. Click it to hide the variables.


Unfortunately, this is not possible in the current version of Visual Studio. In C++, the IntelliSense list is not filtered by accessibility or scope. Therefore, private members are still shown even where they are not actually accessible by your code. There are no settings to tweak this behavior, either.

You just have to rely on the lock icon to indicate that they're private and therefore inaccessible. All of those little icons in the IntelliSense window do have a meaning, you know.

But it looks like this feature might be coming in the next version of Visual Studio (VS11). MSDN says:

List Members Enhancements. The List Members drop-down appears automatically as you type code into the code editor. Results are filtered, so that only relevant members are displayed as you type. You can control the type of filtering logic used by the Member List in the Options dialog box under Text Editor, C/C++, Advanced.

As silly as it is, I'm rather excited about this, too. Along with other cool stuff like better syntax highlighting and reference highlighting. The Developer Preview is out already, so you could try to start using it if you want, but it may not be ready for prime time. And this is admittedly kind of a lousy reason to upgrade...

Alternatively, you could invest in Visual Assist X, which is an extension available for multiple versions of Visual Studio that adds a lot of convenience features to the C++ IDE and, pertinently, improves the IntelliSense filtering. It's not free, but it's pretty awesome for C++ developers, and if I wasn't poor/broke/cheap, I'd definitely buy it myself.