Trouble defining objects

Hi, title describes it really. I am using Dev-C++, and have succesfully defined my first object and used it in a program (hooray!). However, object number 2 is proving troublesome.

I have tried compiling it before really writing anything in the main part of the program - it worked initially, but when I added the three mutator methods it now wont compile, and gives me the error message:

" In member function `void Date::setDay(int)':
a function-definition is not allowed here before '{' token "

for each of the three methods. But I thought you had to define a variable to use in the implementation of a method at this point? And im pretty sure that's what I did on the one that worked. Anyway, here is the code:

Header:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
using namespace std;

class Date {
      private:
              int day, month, year;
      public: 
            Date (); // contructor
            
            void setDay (int); // mutators
            void setMonth (int);
            void setYear (int);
            
            void printFormatted () const; 
     
};  



Implementation:


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <iostream>
#include "date.h" // change me

using namespace std;

Date::Date ()
{
     return;
}
       
void Date::setDay (int newDay)
{
     day = newDay;
     return;
{
     
void Date::setMonth (int newMonth)
{
     month = newMonth;
     return;
}

void Date::setYear (int newYear)
{
     year = newYear;
     return;
}
   
void Date::printFormatted () const
{
     cout << day ;
     
     switch (day)
     {
            case 1:
            case 21:
            case 31: cout << "st " ;
                     break;
            case 2:
            case 22: cout << "nd " ;
                     break;
            case 3:
            case 23: cout << "rd " ;
                     break;
            default: cout << "th " ;
     }
     
     cout << month << " " << year << endl ;
     return;
}          


Main body (such as it is)


1
2
3
4
5
6
7
8
9
10
11
12
#include <cstdlib>
#include <iostream>
#include <string>
#include "date.h"

using namespace std;

int main(int argc, char *argv[])
{
    system("PAUSE");
    return EXIT_SUCCESS;
}

Apologies if it's slap-yourself-in-the-face-blindingly-obvious, but its really frustrating me!
At the end of void Date::setDay (int newDay), { should be }
Argh, can't believe I didn't spot that. Thanks very much
Topic archived. No new replies allowed.