Click here to Skip to main content
15,886,806 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I met this class definition in my study:
class style{
DWORD getExtWindowStyle();
HWND  getWindowOwner();
DWORD getWindowStyle();

BOOL maximizeButton;
BOOL minimizeButton;
BOOL helpButton;
BOOL systemMenu;
BOOL title;
BOOL ScrollBars;
BOOL owned;
int  border;
int  edge;
BOOL clipSiblings;
BOOL alwaysOnTop;
BOOL acceptFiles;
BOOL toolWindow;
int  windowType;

#define CHILD0
#define POPUP1
}


What is the purpose of these two #define statements? try to get more insight from C++ gurus here.

What I have tried:

I know how #define statement works, does it mean they define some macro inside this class?
Posted
Updated 19-Jun-21 10:26am
Comments
KarstenK 20-Jun-21 3:22am    
Use such define with great care, because compilers arent good to yell at errors, so you main earn strange errors. Better is to think about other solutions like const values.

You could call them macros, but all they define is the two names, no different than an #include guard. Somewhere there is probably another preprocessor directive that says
C++
#ifdef CHILD0
   // code to be conditionally compiled
#endif
Macro names are global and do not belong to a specific class or namespace.
 
Share this answer
 
v2
Comments
Southmountain 19-Jun-21 16:32pm    
your explanation makes sense to me now. thank you for your time!
Quote:
How to understand this #define statement in C++ class definition?

As is in this code, it define 2 names that does nothing.
But such defines are usually used for conditional compilation.
Preprocessor directives - C++ Tutorials[^]
C/C++ Preprocessors - GeeksforGeeks[^]
 
Share this answer
 
Comments
Southmountain 19-Jun-21 16:34pm    
so from the point where #define statement is, the defined macro is effective for conditional compilation.
Patrice T 19-Jun-21 17:07pm    
Only rest of code can tell you.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900