主题:C++求助一下,路过大神……
下面三个文件中分别放了一部分代码,但是不能运行。求帮助啊
//date.cpp -------------------------定义类中的函数
#include<iostream>
#include<iomanip>
#include"date.h"
using namespace std;
void Date::set(int y,int m,int d){
year=y; month=m; day=d;
}
void Date::add(){
month +=1;
}
void Date::print(){
cout<<setw(2)<<setfill('0')<<day<<"/"
<<setw(2)<<setfill('0')<<month<<"/"
<<year<<'\n';
}
//date.h ------------------------------------------------
class Date{
int year, month, day;
public:
void set(int y,int m,int d);
void add();
void print();
};
//file.cpp ------------------------------------------
#include<iostream>
#include"date.h"
using namespace std;
int main()
{
Date today;
today.set(2011,11,16);
today.add();
today.print();
}[/color]上面这个程序运行时编译通过,但是连接是有如下问题,求大神帮助:
file.obj : error LNK2001: unresolved external symbol "public: void __thiscall Date::print(void)" (?print@Date@@QAEXXZ)
file.obj : error LNK2001: unresolved external symbol "public: void __thiscall Date::add(void)" (?add@Date@@QAEXXZ)
file.obj : error LNK2001: unresolved external symbol "public: void __thiscall Date::set(int,int,int)" (?set@Date@@QAEXHHH@Z)
Debug/file.exe : fatal error LNK1120: 3 unresolved externals
//date.cpp -------------------------定义类中的函数
#include<iostream>
#include<iomanip>
#include"date.h"
using namespace std;
void Date::set(int y,int m,int d){
year=y; month=m; day=d;
}
void Date::add(){
month +=1;
}
void Date::print(){
cout<<setw(2)<<setfill('0')<<day<<"/"
<<setw(2)<<setfill('0')<<month<<"/"
<<year<<'\n';
}
//date.h ------------------------------------------------
class Date{
int year, month, day;
public:
void set(int y,int m,int d);
void add();
void print();
};
//file.cpp ------------------------------------------
#include<iostream>
#include"date.h"
using namespace std;
int main()
{
Date today;
today.set(2011,11,16);
today.add();
today.print();
}[/color]上面这个程序运行时编译通过,但是连接是有如下问题,求大神帮助:
file.obj : error LNK2001: unresolved external symbol "public: void __thiscall Date::print(void)" (?print@Date@@QAEXXZ)
file.obj : error LNK2001: unresolved external symbol "public: void __thiscall Date::add(void)" (?add@Date@@QAEXXZ)
file.obj : error LNK2001: unresolved external symbol "public: void __thiscall Date::set(int,int,int)" (?set@Date@@QAEXHHH@Z)
Debug/file.exe : fatal error LNK1120: 3 unresolved externals