所以我有這個練習是創建一個默認的構造函數DayOfYear,它將有一天設置爲1月1日。所以該構造它會主要有以下稱爲:默認構造函數C++頭和cpp
int main()
{
DayOfYear someDay;
someDay.output();
return 0;
}
所以我有這樣的標題:
#include <iostream>
#include <cstdlib>
class DayOfYear
{
public:
int month;
int day;
void output();
DayOfYear();
};
及以下CPP:
#include <iostream>
#include <cstdlib>
#include "DayOfYear.h"
using namespace std;
DayOfYear::DayOfYear() :month(1), day(1)
{
}
所以我越來越許多錯誤,我已經嘗試了很多東西,但我不知道有什麼問題。這些錯誤是;
In file included from main.cpp:2:0:
DayOfYear.h:9: error: ISO C++ forbids declaration of ‘output’ with no type [-fpermissive]
DayOfYear:: output();
^
DayOfYear.h:9: error: extra qualification ‘DayOfYear::’ on member ‘output’ [-fpermissive]
DayOfYear:: output();
^
In file included from DayOfYear.cpp:3:
DayOfYear.h:9: error: ISO C++ forbids declaration of ‘output’ with no type [-fpermissive]
DayOfYear:: output();
^
DayOfYear.h:9: error: extra qualification ‘DayOfYear::’ on member ‘output’ [-fpermissive]
DayOfYear:: output();
最好是有'詮釋month'等私人 - 然後使用getter/setter方法 –
哪裏是'無效輸出()'定義是什麼? –
您的錯誤消息似乎與您所顯示的代碼不符。 – NathanOliver