CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4

Threaded View

  1. #1
    Join Date
    Oct 2009
    Posts
    40

    Problem with enum

    I am trying to run an example from a book I read.

    "
    #include <stdio.h>

    enum months { Jan,Feb,Mar,Apr,Jun,Jul,Aug,Sep,Oct,Nov,Dec};

    int main()

    {
    enum months month;
    const char* monthName[]= { "","January","February","March","April","May","June","July","August","September","October","November","December"};

    for (month=Jan;month<=Dec;month++)
    printf("&#37;2d%11s\n",month,monthName[month]);

    return 0;

    }
    "

    This code gives these errors:

    main.cpp:35: error: no 'operator++(int)' declared for postfix '++', trying prefix operator instead
    main.cpp:35: error: no match for 'operator++' in '++month'

    Like you see "month++" in for loop's beginning gives the error but in the book it is written as that...
    Last edited by AwArEnEsS; March 26th, 2012 at 11:15 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured