C++"undefined reference to ......"

ada*_*ges -1 c++ compiler-errors

我无法弄清楚为什么我的代码坏了,我可以使用一些帮助.

首先,代码:

Timer.h:

#include [...]

class Timer {
    public:
        [...]
        Timer operator+(double);
        [...]
    private:
        [...]
        void correctthedate(int day, int month, int year);
        [...]
};
Run Code Online (Sandbox Code Playgroud)

Timer.cc:

#include "Timer.h"
using namespace std;

[...]

void correctthedate(int day, int month, int year) {
    [...]
}

[...]

Timer Timer::operator+(double plush) {
    [...]
    correctthedate(curday, curmonth, curyear);
    return *this;
}
Run Code Online (Sandbox Code Playgroud)

当我尝试编译时,我收到错误:

Timer.o: In function `Timer::operator+(double)':
Timer.cc:(.text+0x1ad3): undefined reference to `Timer::correctthedate(int, int, int)'
Run Code Online (Sandbox Code Playgroud)

任何正确方向的指针?谢谢!

NPE*_*NPE 7

以下行:

void correctthedate(int day, int month, int year) {
Run Code Online (Sandbox Code Playgroud)

应该读

void Timer::correctthedate(int day, int month, int year) {
Run Code Online (Sandbox Code Playgroud)

否则你只是定义一个名为的无关函数correctthedate().


spr*_*aff 5

void Timer::correctthedate(int day, int month, int year) {
Run Code Online (Sandbox Code Playgroud)

你的correctthedate定义是一个自由函数,虽然没有原型.你必须用这个名字来限定名字Timer::