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 ?
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 ?
Never end on learning~
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.
>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
My best code is written with the delete key.
The only usage of #define in C++: as preprocess instruct. like this:
Code:#ifdef _DEBUG TRACE0("Some error occur..."); #endif abort();
Hello, everyone.
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);
Last edited by Okiesmokie; 05-09-2002 at 06:07 PM.
"There are three kinds of people in the world...
Those that can count and those that can't."
Prelude, I know you are the man (or woman in this case ) 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~
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~
Never end on learning~
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.
Last edited by Hotman_x; 05-09-2002 at 10:00 PM.
Hello, everyone.