CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2009
    Posts
    24

    Question Class header help???

    I'm trying to make a class that makes a date and lets the user edit the date.

    date.h
    Code:
    #ifndef date
    #define date
    
    #include <iostream>
    #include <string>
    
    using namespace std;
    
    class date
      {
        private:
          enum m_e_month
          {
            January=1,
            Febuary=2,
            March=3,
            April=4,
            May=5,
            June=6,
            July=7,
            August=8,
            September=9,
            October=10,
            November=11,
            December=12
          };
          m_e_month m_month;
          short int m_sh_I_year;
          short int m_sh_I_day;
          void makeyear()
            {
              cout<<"enter the year:";
              cin>>m_sh_I_year;
            }
          void makemonth()
            {
              bool redo=1;
              cout<<"Enter the month's name it must be capitalied.";
              while(redo)
                {
                  string tmonth="0";
                  cin>>tmonth;
                  ///////////////////////////////////////////////It set to 0 so is assumes nothings going to happen. If it weren't here thaen and infinite loop would start.
                  redo=0;
                  ///////////////////////////////////////////////I have to use ifs because switchs don't work.
                  if(tmonth=="January")
                      {m_month=January;}
                  else if(tmonth=="Febuary")
                      {m_month=Febuary;}
                  else if(tmonth=="March")
                      {m_month=March;}
                  else if(tmonth=="April")
                      {m_month=April;}
                  else if(tmonth=="May")
                      {m_month=May;}
                  else if(tmonth=="June")
                      {m_month=June;}
                  else if(tmonth=="July")
                      {m_month=July;}
                  else if(tmonth=="August")
                      {m_month=August;}
                  else if(tmonth=="September")
                      {m_month=September;}
                  else if(tmonth=="October")
                      {m_month=October;}
                  else if(tmonth=="November")
                      {m_month=November;}
                  else if(tmonth=="December")
                      {m_month=December;}
                  else
                  {redo=1;cout<<"invalad please try again:";}
                }
            }
          void makeday()
            {
              cout<<"enter the day(number)";
              cin>>m_sh_I_day;
            }
        public:
          date(int a=0, m_e_month b=January, int c=-1)
            {
              m_sh_I_year=a;
              m_month=b;
              m_sh_I_day=c;
            }
          void printdate()
            {
              cout<<m_sh_I_year<<"/"
              <<m_month<<"/"
              <<m_sh_I_day;
            }
          void makedate()
            {
              makeyear();
              makemonth();
              makeday();
            }
      };
    
    #endif
    I end up with a whole bunch of bugs that are alien to me.

    80|error: expected unqualified-id before "int"
    80|error: expected `)' before "int"
    10|error: an anonymous union cannot have function members
    98|error: abstract declarator `<anonymous class>' used as declaration

  2. #2
    Join Date
    Nov 2003
    Location
    Belgium
    Posts
    8,150

    Re: Class header help???

    You cannot do:
    Code:
    #define date
    and then define a class with the same name. That is causing all kinds of weird errors.
    instead do something like:
    Code:
    #ifndef DATE_H
    #define DATE_H
    Marc Gregoire - NuonSoft (http://www.nuonsoft.com)
    My Blog
    Wallpaper Cycler 3.5.0.97

    Author of Professional C++, 4th Edition by Wiley/Wrox (includes C++17 features)
    ISBN: 978-1-119-42130-6
    [ http://www.facebook.com/professionalcpp ]

  3. #3
    Join Date
    Mar 2008
    Posts
    30

    Re: Class header help???

    this reply has nothing to do to your problem
    it would be better if you define enumerated constant m_e_month like this:
    Code:
    enum m_e_month {
    January=1,
    February,
    March,
    April,
    May,
    June,
    July,
    August,
    September,
    October,
    November,
    December
    };
    another thing, use inline functions wisely

Tags for this Thread

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