Function Declaration in Interface File :: MFC

kuphryn

Senior member
Jan 7, 2001
400
0
0
Hi.

Regarding C++ windows programming, is it a convention to include both data type and variables names for function parameters in the declaration file?

For example:


class MyFrame : public CFrameWnd{public: MyFrame(); functionA(int &var, char &str); protected: afx_msg OnPaint(); afx_msg OnLButtonDown(UINT nChar, UINT nRep, UINT nFlags);// afx_msg OnLButtonDown(UINT, UINT, UINT);...private:...};


I am used to not including anything more than what is necessary.

Kuphryn
 

DaveSimmons

Elite Member
Aug 12, 2001
40,730
670
126
In general the variable names are very helpful both as documentation and since they are shown by the "intellisense" tooltip when you go to use the function later -- for example if you create:
StrIStr( char* pbuffer, char* seeking )

then when you go to use the function, as you type the IDE will remind you that the first function argument is the buffer and not the string you are looking to find. It's also clearer if you're reading the .h file later.

In the above you'd probably want "const char* seeking" but think about other functions with 2+ of any thing, like foo(char *, int, int) vs. foo(char* buffer, int start, int end)

I'll admit the names are less necessary for "standard" MFC message and virtual functions like OnSize(), but at work we usually let ClassWizard generate those anyway.
 

kuphryn

Senior member
Jan 7, 2001
400
0
0
Okay. Thanks.

I am seeing something interesting about program philosophy especially C++. I remember when I first began learning C++ last fall. Every book I read, including Gaddis and Deitel&Deitel, prefer to "hide" the variable name in the declaration file. Now with MFC, I find that Microsoft is more into *convention* and *easy user*. MFC is a well organized "package." For example, the member variables all start with "m" and "m_p."

Kuphryn