Click here to Skip to main content
15,923,222 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: Looking for panacea...Type of the control...I have only CWnd pointer Pin
Jon Hulatt6-Dec-01 22:29
Jon Hulatt6-Dec-01 22:29 
GeneralPlease Help !!! Pin
The_Server6-Dec-01 1:26
The_Server6-Dec-01 1:26 
GeneralRe: Please Help !!! Pin
Jon Hulatt6-Dec-01 2:28
Jon Hulatt6-Dec-01 2:28 
GeneralRe: Please Help !!! Pin
Christian Graus6-Dec-01 9:19
protectorChristian Graus6-Dec-01 9:19 
GeneralEnum... Pin
Bernhard6-Dec-01 1:10
Bernhard6-Dec-01 1:10 
GeneralRe: Enum... Pin
BlackSmith6-Dec-01 11:00
BlackSmith6-Dec-01 11:00 
GeneralThank you all for your great help Pin
Bernhard6-Dec-01 19:20
Bernhard6-Dec-01 19:20 
GeneralRe: Enum... Pin
Shog96-Dec-01 12:42
sitebuilderShog96-Dec-01 12:42 
Bernhard wrote:
* "thinking in c++" said that you should use static const - var's instead of enums, is this really better ?

I hate blanket statements like that... Enums should be used for what they are meant for -- enumerations. That is, they should be used when you need to represent a set of values, but don't really care what the values are:


enum ACTION
{
   PRINT,
   PREVIEW,
   EXPORT
};

void DoOutput(const char* OutputDataString, ACTION action)
{
   switch (action)
   {
      case PRINT:
      ...
      break;
      case PREVIEW:
      ...
      break;
      case EXPORT:
      ...
      break;
   }
}

In the example above, it doesn't matter what the values of PRINT, PREVIEW, and EXPORT are, only that they are different. As the other post mentioned, the compiler will perform type checking on this to ensure that only valid values are passed into the function (of course you could use a cast, but you'd never do that right?).


In cases where the value of a constant is actually important, you should use a static const -- not only does this let you be consistent about your constants, since enums are only good for ints anyway, it is also safer, since if the value is important, sooner or later you'll need to convert it from something else, and assigning an int to an enum variable is (i think) undefined (though it usually works). If you need some extra type checking in this case, you're better off using a typedef or even a wrapper class.



Just my $.02 Big Grin | :-D
GeneralRe: Enum... Pin
Michael Dunn6-Dec-01 13:32
sitebuilderMichael Dunn6-Dec-01 13:32 
GeneralFinding proper documentation for AddIn Interfaces Pin
Franz Klein5-Dec-01 23:24
Franz Klein5-Dec-01 23:24 
GeneralError in calling resource function Pin
5-Dec-01 22:36
suss5-Dec-01 22:36 
GeneralBeginner : using .INI files Pin
Jerome Conus5-Dec-01 22:11
Jerome Conus5-Dec-01 22:11 
GeneralRe: Beginner : using .INI files Pin
Michael P Butler5-Dec-01 23:36
Michael P Butler5-Dec-01 23:36 
GeneralRe: Beginner : using .INI files Pin
Alvaro Mendez6-Dec-01 10:17
Alvaro Mendez6-Dec-01 10:17 
GeneralThread problem Pin
marutis5-Dec-01 21:57
marutis5-Dec-01 21:57 
QuestionDraw text without HDC, possible? Pin
Baling5-Dec-01 21:18
Baling5-Dec-01 21:18 
AnswerRe: Draw text without HDC, possible? Pin
Chambers6-Dec-01 2:23
Chambers6-Dec-01 2:23 
GeneralRe: Draw text without HDC, possible? Pin
Baling6-Dec-01 5:11
Baling6-Dec-01 5:11 
QuestionHow to control Display Pin
binnu5-Dec-01 20:01
binnu5-Dec-01 20:01 
GeneralDynamic IP address Pin
5-Dec-01 19:16
suss5-Dec-01 19:16 
GeneralRe: Dynamic IP address Pin
Gennady Oster5-Dec-01 20:36
Gennady Oster5-Dec-01 20:36 
GeneralMost Impacting/Powerful Future Programming Language Pin
valikac5-Dec-01 18:19
valikac5-Dec-01 18:19 
GeneralAny 'C' equivalent to Code Project Pin
SAK5-Dec-01 14:39
SAK5-Dec-01 14:39 
GeneralRe: Any 'C' equivalent to Code Project Pin
Rickard Andersson205-Dec-01 21:27
Rickard Andersson205-Dec-01 21:27 
GeneralHTTP file download flow control help needed Pin
Wolfram Steinke5-Dec-01 13:48
Wolfram Steinke5-Dec-01 13:48 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.