2014-11-03 44 views
0

我在我的代碼有一些錯誤,我無法弄清楚如何解決它們。我試圖谷歌類似的錯誤,但我無法解決我一直有問題。預計在C++中使用class的非限定id錯誤?

繼承人我的代碼:

#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; 

} 

這裏是我的錯誤:

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!

+2

'int Date :: getDay()const;'壞的分號。 – 2014-11-03 02:35:04

回答

3

像尼爾已經表示,在評論

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

應該

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

,所以它也是得到月和得到年

哪裏是GETDATE的定義哪裏去了?

相關問題