回 帖 发 新 帖 刷新版面

主题: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

回复列表 (共5个回复)

沙发

查了一下,好像说是没有定义函数,怎么回事?

板凳

你类的定义怎么在类函数定义的后面啊,先定义类再定义类内部的函数

3 楼

开发环境的问题,你用的是什么IDE?

4 楼


提问:一群猪(n只)围成一圈,任意假定一个数i,从第一只猪数起,数到第i只的时候,这只猪离开,依次这样数下去,最后剩下的一只就是蠢猪!求蠢猪的初始位置m?
该怎么编,我是刚刚入门的

5 楼

头文件是Date.h

我来回复

您尚未登录,请登录后再回复。点此登录或注册