error C2664

This is a discussion on error C2664 within the C++ Programming forums, part of the General Programming Boards category; I have this code that I am trying to compile and I keep getting an error C2664 message. I am ...

  1. #1
    Registered User
    Join Date
    Feb 2006
    Posts
    14

    Question error C2664

    I have this code that I am trying to compile and I keep getting an error C2664 message. I am not sure what to do with the code that it is pointing to. (This is just part of the program code but I get this same error in another part of the code)
    Code:
    #include <iostream>
    
    using std::cout;
    using std::endl;
    
    #include <ctime>
    
    #include <cstdlib>
    
    enum Months { JAN = 1, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC };
    
    void generateDate( int &, int &, int );
    void printDate( Months, int, int );
    int validDate( int, int );
    
    int main()
    {
        int month = 1;
        int day = 1;
        int year = 1900;
    	int getYear;
    	int getMonth;
    	int getDay;
    	int Month;
    	int myMonth;
    
        srand( time( 0 ) );
    
        printDate( month, day, year );
        year = getYear ( year );
        month = getMonth( month );
        day = getDay( day );
    
        if (validDate (month, day, year) == true )
            printDate ( month, day, year );
    
        return 0;
    
    }   // end main
    This is the whole error message:
    error C2664: 'printDate' : cannot convert parameter 1 from 'int' to 'enum Months'
    Conversion to enumeration type requires an explicit cast (static_cast, C-style cast or function-style cast)

    Any help will be appreciated.

  2. #2
    Mad OnionKnight's Avatar
    Join Date
    Jan 2005
    Location
    Umeň, Sweden
    Posts
    555
    Change
    Code:
    int month = 1;
    to
    Code:
    Months month = JAN;

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21