guillotinechan
guillotinechan

Reputation: 3

expected unqualified-id error with class in C++?

I'm having some errors in my code and I can't figure out how to fix them. I tried to google similar errors but I couldn't resolve the issues i've been having.

Heres my code:

#include <iostream>

using namespace std;

class Date
{
private:
int year;
int month;
int day;

public:
    void setDay(int);
    void setMonth(int);
    void setYear(int);
    int getDay() const;
    int getMonth() const;
    int getYear() const;
    int getDate() const;

};


void Date::setDay(int d)
{
day = d;
}

void Date::setMonth(int m)
{
month = m;
}



void Date::setYear(int y)
{
year = y;
}


int Date::getDay() const;
{   
return day;
}



int Date::getMonth() const;
{
return month;
}

int Date::getYear() const;
{
return year;
}



int main() {

Date dat;
int datDay; //local variable for day
int datMon; //local variable for month
int datYea; //local variable for year

cout << "What is the day?";
cin >> datDay;

cout << "What is the month?";
cin >> datMon;

cout << "What is the year?";
cin >> datYea;

dat.setDay(datDay);
dat.setMonth(datMon);
dat.setYear(datYea);

//display
cout << "Day: " << dat.getDay() << endl;
cout << "Month: " << dat.getMonth() << endl;
cout << "Year: " << dat.getYear() << endl;
return 0;

}

And here are my errors:

gr_hw8.cpp:26:1: error: expected unqualified-id
void Date::setDay(int d)
^
gr_hw8.cpp:33:1: error: expected unqualified-id
void Date::setMonth(int m)
^
gr_hw8.cpp:40:1: error: expected unqualified-id
void Date::setYear(int y)
^
gr_hw8.cpp:47:1: error: expected unqualified-id
int Date::getDay() const;
^
gr_hw8.cpp:48:1: error: expected unqualified-id
{       
^
gr_hw8.cpp:54:1: error: expected unqualified-id
int Date::getMonth() const;
^
gr_hw8.cpp:55:1: error: expected unqualified-id
{
^
gr_hw8.cpp:60:1: error: expected unqualified-id
int Date::getYear() const;
^
gr_hw8.cpp:61:1: error: expected unqualified-id
{
^
gr_hw8.cpp:68:1: error: expected unqualified-id
int main() {
^
10 errors generated.

Thannks!!

Upvotes: 0

Views: 1819

Answers (1)

progsource
progsource

Reputation: 639

Like Neil said already in the comments

int Date::getDay() const;
{   
return day;
}

should be

int Date::getDay() const
{   
return day;
}

and so it is also for getMonth and getYear

Where is the definition of getDate gone?

Upvotes: 3

Related Questions