我已阅读:未定义对 `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;
}
我调用它的 main ,只是因为我不确定错误是否是因为它没有被调用或类似的东西:
#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;
}
在与注册相关的重载 >> 运算符中未设置日期。它由基本构造函数设置。
同样,我没有将此类添加到程序中,因为它将是我只是在编写并以基本测试方式添加后尝试编译。通过 main 进行测试。
提前致谢。=D