我已閱讀:undefined reference to `[email protected]' &仍然不明白我的問題。未定義引用WinMain @ 16 - 代碼塊
我有一個工作的程序。添加了一個類,但沒有將它實現到程序中,而只是寫了頭文件和.cpp文件。剛剛添加這個類的程序工作,現在不行。
錯誤狀態...... **文件地址.... libmingw.32.a(main.o),此:main.c中:(text.startup + 0xa7)
頭文件
#ifndef DATE_H
#define DATE_H
#include <iostream>
#include <string>
class Date
{
public:
Date();
//Setters
void SetDay(unsigned dy);
void SetMonth(std::string month);
void SetYear(unsigned mnth);
//Getters
unsigned GetDay() const;
std::string GetMonth() const;
unsigned GetYear() const;
private:
unsigned day, year;
std::string month;
};
#endif // DATE_H
.cpp文件
#include "Date.h"
Date::Date()
{
day = 0;
year = 0;
month = "Not Set";
}
//Setters
void Date::SetDay(unsigned dy)
{
day = dy;
}
void Date::SetMonth(std::string mnth)
{
month = mnth;
}
void Date::SetYear(unsigned yr)
{
year = yr;
}
//Getters
unsigned Date::GetDay() const
{
return day;
}
unsigned Date::GetYear() const
{
return year;
}
std::string Date::GetMonth() const
{
return month;
}
我的主,我在稱呼它,只是因爲我不知道是否是因爲它沒有被稱爲誤差或類似的東西是:
#include <iostream>
#include <fstream>
#include "unit.h" // Unit class declaration
#include "regist.h" // Registration class declaration
#include "date.h"
using namespace std;
// Main program:
// Open an input file stream, read a Registration object,
// including its list of courses. Redisplay all information,
// and calculate the total credits taken. Write the results
// to a file stream.
int main()
{
ifstream infile("testin.txt");
if(!infile) return -1;
Registration R;
Date D;
infile >> R;
ofstream ofile("testout.txt");
ofile << R;
cout << "\nComputation completed. Check output file. \n";
cout << "\n Day is " << D.GetDay;
return 0;
}
不會在與註冊有關的超載>>操作符中設置日期。它由基本的構造函數設置。
我再次沒有將這個類加入到程序中,因爲它只是在編寫和添加基本測試方式後才編譯。通過主測試。
在此先感謝。 = D
因此,它僅適用於主要功能,但不適用於添加的類。你確定你編譯並鏈接了兩個.cpp文件嗎? – chris 2015-04-02 04:30:43
即使該類未鏈接,它只是項目的一部分,但未被使用。它仍然有相同的錯誤。 – 2015-04-02 06:54:39
是否有可能已經有一個名爲date.h的庫,因此出現錯誤? – 2015-04-03 01:54:11