Hide a function or variable from the Class View



The Class View displays all the functions defined in a class (even global functions) but it does not provide any means of organizing them. With more and more functions in a class the Class View becomes less and less useful. With too many functions listed you need to scroll more often and it takes a while longer to find the function. We can alleviate the situation by hiding trivial function from the Class View. Functions such as the trivial OnUpdateXXXX functions are ideal candidates.

The Class View (and the Class Wizard and the Wizard Bar) does not support hiding of functions.
It, however, preprocess the file and we use use this knowledge to fool it into not recognizing a function.
To achieve this we declare a couple of macros to camouflage the parentheses.
If there is more than one class that you want to hide functions in, you may want
to declare the macros in stdafx.h, otherwise declaring it in the header file for the class is OK.

Make sure you document this in each header file you modify, otherwise your code is going to be
a big headache for the next person seeing it.

#define HIDE____ (
#define ____HIDE );

The first macro is used for the starting paren and the second macro for the ending parent and the semi colon.

Here’s how you would hide a function

Change

	afx_msg void OnUpdateFunction(CCmdUI* pCmdUI);

To

	afx_msg void OnUpdateFunction HIDE___ CCmdUI* pCmdUI ___HIDE

Note that there is no ending semi-colon. That’s taken care of by the macro.

To hide a variable, define a macro to substitute for the semi-colon. Use this macro to end the
statement

More by Author

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Must Read