2011-10-18 8 views
-1

私のコードが壊れている理由がわかりません。すべてのC++ "undefined reference to ..."

まず、コード:

Timer.h:

#include [...] 

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

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; 
} 

私がコンパイルしようとすると、私はエラーを取得:

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

右のdirのポインタ何か?ありがとう!

+0

時間/タイマー?ここにはミックスがあります。 – crashmstr

答えて

7

次の行で名前を修飾する必要があります。

void correctthedate(int day, int month, int year) { 

は、そうでなければ、あなただけのcorrectthedate()と呼ばれる関係のない機能を定義している

void Timer::correctthedate(int day, int month, int year) { 

をお読みください。

+0

驚くばかり!どうもありがとう! – adammenges

+1

これまでにこの間違いをしたことがある人なら誰でも手を挙げてください:!_! –

5

void Timer::correctthedate(int day, int month, int year) { 

を書くあなたのcorrectthedate定義は、プロトタイプのないものとはいえ、無料の機能です。あなたはTimer::

2

これを置き換えます。これにより

void correctthedate(int day, int month, int year) { 

Timer::correctthedate(int day, int month, int year) { 

をお使いのバージョンでは、correctthedateは普通の関数であり、ちょうどので、それは方法の一つとして同じ名前を持つことが起こりますTimeです。 Time::correctthedateは、定義を持たない完全に異なる関数(メソッド)であるため、リンカーはそれを見つけることができないと不平を言います。

1

お客様のヘッダーには、Timer::operator+Timer::correctthedateの機能が宣言されています。
あなたのcppはTimer::operator+::correcttehdateの機能を定義しています。
リンカーはTimer::correctthedateを見つけることができません。

答えはvoid correctthedate(int...void Timer::correctthedate(int...に変更することです。