C++ define statements == what in C#?
-
in C++ i would have something like this:
#define DIALUP 0
#define FTP 1
..
if (m_nAccessMode == FTP)
..this was really useful for keeping track of options and such, like if im storing a combo box of
Monthly
,Quarterly
,Annually
i dont wanna just compare strings when im doing an if statement, but rather use some sort of defined key so that i never get my stuff mixed up.. i have looked at the#define
statement in C# and it only lets me define like#define FTP
it doesnt let me assign a value to it in the define statement, so i really dont even see its purpose :confused: .. can someone set me straight plz? still a newb.. cut me some slack :P -dz
-
in C++ i would have something like this:
#define DIALUP 0
#define FTP 1
..
if (m_nAccessMode == FTP)
..this was really useful for keeping track of options and such, like if im storing a combo box of
Monthly
,Quarterly
,Annually
i dont wanna just compare strings when im doing an if statement, but rather use some sort of defined key so that i never get my stuff mixed up.. i have looked at the#define
statement in C# and it only lets me define like#define FTP
it doesnt let me assign a value to it in the define statement, so i really dont even see its purpose :confused: .. can someone set me straight plz? still a newb.. cut me some slack :P -dz
it sounds like your trying to do an enumeration. enum Days {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri}; If you look it up at msdn youll be all set. Ryan
-
it sounds like your trying to do an enumeration. enum Days {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri}; If you look it up at msdn youll be all set. Ryan
-
in C++ i would have something like this:
#define DIALUP 0
#define FTP 1
..
if (m_nAccessMode == FTP)
..this was really useful for keeping track of options and such, like if im storing a combo box of
Monthly
,Quarterly
,Annually
i dont wanna just compare strings when im doing an if statement, but rather use some sort of defined key so that i never get my stuff mixed up.. i have looked at the#define
statement in C# and it only lets me define like#define FTP
it doesnt let me assign a value to it in the define statement, so i really dont even see its purpose :confused: .. can someone set me straight plz? still a newb.. cut me some slack :P -dz
This is actually bad practice in C++. You should use const declarations instead. const int DIALUP = 0; or enums, as another poster has suggested. The #define in C# is for conditional compilation. And it should be used like this in C++ also. See, for example, Scott Meyers's "Effective C++" Kevin
-
it sounds like your trying to do an enumeration. enum Days {Sat=1, Sun, Mon, Tue, Wed, Thu, Fri}; If you look it up at msdn youll be all set. Ryan
-
Any reasons C/C++ programmers steer away from enums? All I ever see is defines... Hey leppie! Your "proof" seems brilliant and absurd at the same time. - Vikram Punathambekar 28 Apr '03
In pure C programs you should expect to see lots of #defines. In pure C++ programs you should expect to see none (it's poor practice - see http://www.parashift.com/c++-faq-lite/newbie.html#faq-29.7[^]) but you often do. Kevin