Why is Visual Studio intellisense showing private members and functions?

When working with native C ++ in Visual Studio, intellisense displays private members and functions, even if they are not in the scope of the class. This makes it difficult to create clean APIs for the classes I'm writing.

Is there a reason for this? Can this be prevented?

+7
source share
3 answers

Well, why not show private ones? They are members, after all, they exist, and they are perfectly accessible from certain contexts, like any other members.

It would be very difficult for IntelliSense to determine whether members are accessible or not from this particular context, especially considering that in most cases this context is not yet completed (the user still prints it), which means that it is impossible to analyze at all.

+2
source

The reason, perhaps, only Microsoft knows. (I think Intellisense does not check where you are at the moment, so it does not know if you are inside the class (and can access private members) or outside)

In fact, I do not know how and how this can be prevented.
But as far as I know, they have an Icon with a lock, so you know that they are private. Maybe it helps

+3
source

Unfortunately, this only works on what you are doing, but it still needs to be kept in mind if you use a lot of your own libraries.

One thing I have done for any libraries I do is try to trick intellisense C # define. In the class declaration in the header file for any library that I create, I surround the entire private part in #ifdef space, for example

#ifdef MYCLASS_SHOW_PRIVATE_VARIABLES private: int hideThisVariable; float noShow; void HiddenIncrementFunction(); #endif 

Then in the class code section, where I need to provide definitions for all methods, at the top, before I include the class declaration file, I add

 #define MYCLASS_SHOW_PRIVATE_VARIABLES 

Thus, private members are visible only to those methods that you implement for your class in the source file. Any clients using this library will not be able to see private variables through intellisense, unless, of course, they can determine your processor directive.

0
source

All Articles