2011-10-18 5 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)' 

오른쪽 영역의 모든 포인터 임무? 감사!

+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...으로 변경하는 것입니다.

관련 문제