Click here to Skip to main content
15,920,687 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: ip adress Pin
ThatsAlok5-Jul-05 21:35
ThatsAlok5-Jul-05 21:35 
GeneralFont Problem Pin
Pazzuzu5-Jul-05 20:46
Pazzuzu5-Jul-05 20:46 
QuestionTo delete functions via IDE of VC++ 2003 ? Pin
Maxwell Chen5-Jul-05 20:45
Maxwell Chen5-Jul-05 20:45 
Generalopening MDI in maximized form at startup Pin
sayup5-Jul-05 20:15
sayup5-Jul-05 20:15 
GeneralRe: opening MDI in maximized form at startup Pin
Antony T5-Jul-05 22:48
sussAntony T5-Jul-05 22:48 
Generalenum in a switch statement Pin
Ista5-Jul-05 20:13
Ista5-Jul-05 20:13 
GeneralRe: enum in a switch statement Pin
ThatsAlok5-Jul-05 20:26
ThatsAlok5-Jul-05 20:26 
GeneralRe: enum in a switch statement Pin
Bob Stanneveld5-Jul-05 22:18
Bob Stanneveld5-Jul-05 22:18 
Hello,

You have several problems in your code! They may not seem to be a problem at first sight, but eventually they will lead to trouble. Some of your errors are in your programming style, others are in your code that causes the compiler to shout error messages at you. Here are the errors that caught at a first look:

enum WordDirection 
{
Right = 0,
Down,
Diag_Down,
Diag_Up 
};


This is not a syntax error, but a more problem in large projects. The reason for this is that in large projects, a lot of names are made up. If you don't put everything in their own namespace or class, name clashes are the inevitable result! A better solutions would be:
namespace WordDirection {
enum Direction { Right = 0,
                 Down, // Shouldn't this be Left?
                 Diag_Down,
                 Diag_Up
               };
} // namespace WordDirection

// or if you don't like namespaces, use a class
class WordDirection
{
public:
    enum Direction { Right = 0,
                     Down, // Shouldn't this be Left?
                     Diag_Down,
                     Diag_Up
                   };
};


Your other problems are with your switch statement:
case (int)WordDirection.RIGHT:


Three problems here:
<list>
  • 1: The typecast. You don't need to typecast integral constants to int. Especially not in constant expressions. The type of constants is int by default.
  • 2: WordDirection.RIGHT WordDirection is not an instance of a class. Therefore the 'operator .' won't work!
    An other thing, if you use enums, all the constants declared in the enum are made publicly available to the namespace in which the enum is declared! Therefore you can just use RIGHT, DOWN, etc..
  • 3: "RIGHT" is in capital letters, while your declaration is not completely in capital letters! The C++ compiler is case sensitive and therefore it will issue an error. You should use "Right" instead.
    A solution to your problem would be:
    case Right:


    Hope this helps Big Grin | :-D



    Behind every great black man...
                ... is the police. - Conspiracy brother


    Blog[^]

  • GeneralRe: enum in a switch statement Pin
    ThatsAlok6-Jul-05 1:44
    ThatsAlok6-Jul-05 1:44 
    GeneralRe: enum in a switch statement Pin
    Bob Stanneveld6-Jul-05 1:47
    Bob Stanneveld6-Jul-05 1:47 
    GeneralRe: enum in a switch statement Pin
    Ista6-Jul-05 8:56
    Ista6-Jul-05 8:56 
    GeneralRe: enum in a switch statement Pin
    Rick York6-Jul-05 11:46
    mveRick York6-Jul-05 11:46 
    GeneralRe: enum in a switch statement Pin
    Ista6-Jul-05 11:51
    Ista6-Jul-05 11:51 
    GeneralRe: enum in a switch statement Pin
    Bob Stanneveld6-Jul-05 20:40
    Bob Stanneveld6-Jul-05 20:40 
    GeneralUsername n Password Pin
    kireken5-Jul-05 19:10
    kireken5-Jul-05 19:10 
    GeneralRe: Username n Password Pin
    Christian Graus5-Jul-05 19:33
    protectorChristian Graus5-Jul-05 19:33 
    GeneralRe: Username n Password Pin
    kireken5-Jul-05 19:48
    kireken5-Jul-05 19:48 
    GeneralRe: Username n Password Pin
    Christian Graus6-Jul-05 11:12
    protectorChristian Graus6-Jul-05 11:12 
    GeneralRe: Username n Password Pin
    Anonymous6-Jul-05 19:46
    Anonymous6-Jul-05 19:46 
    GeneralRe: Username n Password Pin
    Christian Graus6-Jul-05 23:06
    protectorChristian Graus6-Jul-05 23:06 
    Generalwrite text for read only Pin
    Member 20973435-Jul-05 19:08
    Member 20973435-Jul-05 19:08 
    GeneralRe: write text for read only Pin
    Christian Graus5-Jul-05 19:35
    protectorChristian Graus5-Jul-05 19:35 
    GeneralRe: write text for read only Pin
    David Crow6-Jul-05 2:47
    David Crow6-Jul-05 2:47 
    GeneralRe: write text for read only Pin
    Christian Graus6-Jul-05 11:15
    protectorChristian Graus6-Jul-05 11:15 
    QuestionHow to store RTP payload (G.711) to file? Pin
    Ravi Sankar S5-Jul-05 18:35
    Ravi Sankar S5-Jul-05 18:35 

    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.