I find some #define in C codes but it seldom apprears in C++ codes in which book I am scanning. is that replaced by something already ?:rolleyes:
Printable View
I find some #define in C codes but it seldom apprears in C++ codes in which book I am scanning. is that replaced by something already ?:rolleyes:
You can use a #define directive in C++, but it isn't recommended because you can't specify the data type of the constant...most people just use const.
I got it. thanx guy~ :D
>is that replaced by something already ?
In C #define is used for constant literals to make code more readable/portable, and for creating inline macros for efficiency. C++ recommends that const is used instead of #define for literals because more type checking is done and with the addition of the inline keyword for functions the #define macros are obsolete in C++.
-Prelude
The only usage of #define in C++: as preprocess instruct. like this:
Code:#ifdef _DEBUG
TRACE0("Some error occur...");
#endif
abort();
thats not the only usage for #define in C++,
if you are developing windows apps it is easier to use #define for your controls, ie:
[EDIT]
LoL, i was screwed up when i wrote this line:
#define IDC_BUTTON1;
it should be:
#define IDC_BUTTON1 1000
[/EDIT]
Code:#define IDC_BUTTON1 1000
CreateWindowEx( 0,
TEXT("BUTTON"),
TEXT("Button 1"),
WS_VISIBLE |
WS_CHILD |
BS_FLAT // My Favorite Button Style,
0,
0,
100,
30,
hwnd,
(HMENU)IDC_BUTTON1,
hInstance,
NULL);
Prelude, I know you are the man (or woman in this case :D) when it comes to programming, but aren't #defines used a lot when it comes to window options, messages, and stuff like that?
woh~
hot discussion here, aha~ :D
and I am a bit confused with the code in ur posts. but one day I'll figure it out. thanx all guys who posted~ ;)
The usage of #define in Windows Programming is not in C++ Style. Because Windows SDK is based on C language. You can use const UINT instead of #define when you define an resource ID.
the last three words should be: a resource ID. Excuse me. Oh, my poor English.