Thread: error C2065 Help me please

  1. #1
    Registered User
    Join Date
    Jan 2013
    Posts
    3

    error C2065 Help me please

    I'm coding my homework Calendar program but it have error
    (error C2065: 'JANUARY' : undeclared identifier) Help me please.

    Date.h
    Code:
    #ifndef _Date_
    #define _Date_
    using namespace std;
    class Date{
    public:
        enum Month{JANUARY=1,FEBRUARY,MARCH,APRIL,MAY,JUNE,JULY,AUGUST,SEPTEMBER,OCTOBER,NOVEMBER,DECEMBER};
        Date(void);
        Date(int,Date::Month,int);
        Date(Date::Month,int,int);
        int getYear(void);
        Date::Month getMonth(void);
        int getDay(void);
        int daysInMonth(Date::Month,int);
        bool isLeapYear(int);
        string toString(void);
        void setDay(int);
        void setMonth(int);
        void setYear(int);
        string monthToString(Date::Month);
    private:
        int d,y;
        Month m; 
    };
    #endif

    Date.cpp

    Code:
    #include<iostream>
    #include<string>
    #include"Date.h"
    #include<sstream>
    using namespace std;
    Date::Date(void){
        d = 1;
        m = JANUARY;
        y = 2000;
    }
    Date::Date(int dd,Date::Month mm,int yy){
        d = dd;
        m = mm;
        y = yy;
    }
    Date::Date(Date::Month mm,int dd,int yy){
        d = dd;
        m = mm;
        y = yy;
    }
    void main(){
        Date aaa(1,JANUARY,1998);
        
    }
    in main function Date aaa(1,JANUARY,1998);
    error C2065: 'JANUARY' : undeclared identifier
    Last edited by Winhell01; 01-27-2013 at 04:21 AM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Outside the class, you need to fully qualify the name.
    Code:
    int main(){
        Date aaa(1,Date::JANUARY,1998);
         
    }
    Three more things.
    1. main returns int, not void.

    2. Putting "using namespace" inside a header file is poor style.
    If you were writing a library of some sort, and your library user had several namespaces to deal with, they might not appreciate the wholesale inclusion of ::std into their project.

    3. There is no need for all the Date:: scope resolutions within your Date class.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    1,393
    Quote Originally Posted by Salem View Post
    2. Putting "using namespace" inside a header file is poor style.
    If you were writing a library of some sort, and your library user had several namespaces to deal with, they might not appreciate the wholesale inclusion of ::std into their project.
    If you want to put "using namespace" inside a header file, why not do it in the following way?

    Code:
    #ifndef FOO_H
    #define FOO_H
    #include "bar.h"
    
    namespace foo
    {
    using namespace bar;
       // ...
       int foovar = 123;
    }
    
    #endif // FOO_H
    In this case, anyone who includes "foo.h" does not automatically bring in the bar namespace to their source file.

  4. #4
    Registered User
    Join Date
    Jan 2013
    Posts
    3
    Thank you very much but my teacher want to use this form

    Code:
    int main(){
        Date aaa(1,JANUARY,1998);
    
    }
    How i solve it

    thank you

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Then move the enum out of the class.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Jan 2013
    Posts
    3
    Quote Originally Posted by Salem View Post
    Then move the enum out of the class.
    Thank you very much


  7. #7
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error C2065: undeclared identifier
    By Sarge in forum Windows Programming
    Replies: 2
    Last Post: 02-19-2012, 03:22 PM
  2. error C2065: undeclared identifier
    By decxan in forum C++ Programming
    Replies: 2
    Last Post: 02-14-2011, 01:42 PM
  3. error C2065: 'NULL'
    By jamez05 in forum C Programming
    Replies: 4
    Last Post: 07-23-2006, 12:00 PM
  4. Compiler error error C2065: '_beginthreadex; : undeclared identifier
    By Roaring_Tiger in forum Windows Programming
    Replies: 3
    Last Post: 04-29-2003, 01:54 AM
  5. error C2065 undeclared identifier
    By scott27349 in forum C++ Programming
    Replies: 6
    Last Post: 03-10-2002, 04:22 AM