error C2065 Help me please

This is a discussion on error C2065 Help me please within the C++ Programming forums, part of the General Programming Boards category; I'm coding my homework Calendar program but it have error (error C2065: 'JANUARY' : undeclared identifier) Help me please. Date.h ...

  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 03:21 AM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    1,053
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,434
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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をこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,422
    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, 02:22 PM
  2. error C2065: undeclared identifier
    By decxan in forum C++ Programming
    Replies: 2
    Last Post: 02-14-2011, 12: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, 03:22 AM

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