2013-02-21 58 views
3

編譯基本類和頭時出現此錯誤。不知道我是否錯過了明顯的東西?如果需要可以提供任何額外的細節。沒有在類中聲明成員函數 - 編譯出錯時

注意:我在Event.h中添加了#include <string>,錯誤依然存在。

Event.cpp

#include "Event.h" 
#include <string> 

std::string Event::getLabel() { 
    return label; 
} 

Event.h

#ifndef EVENT_H 
#define EVENT_H 

#define EVENT_STOP 0 
#define EVENT_START 1 


class Event { 
private: 

protected: 
    double time; 
    std::string label; 
    int type; // EVENT_START OR EVENT_STOP 

public: 
    std::string getLabel(); 

}; 

#endif 

編譯和錯誤

g++ -c -Wall -pedantic correngine.cpp 
g++ -c -Wall -pedantic CSVManager.cpp 
g++ -c -Wall -pedantic ServerEvent.cpp 
g++ -c -o UPSEvent.o UPSEvent.cpp 
g++ -c -Wall -pedantic CorrelationEngineManager.cpp 
g++ -c -Wall -pedantic Event.cpp 
Event.cpp:4: error: no ‘std::string Event::getLabel()’ member function declared in class ‘Event’ 
make: *** [Event.o] Error 1 

回答

4

您需要在Event.h

頭0
+0

我確實包括它,我仍然得到相同的錯誤。 – user2089851 2013-02-21 03:23:11

+0

你把它包含在錯誤的地方,將它包含在Event.h文件中,而不是Event.cpp – billz 2013-02-21 03:25:54

+0

我明確地將它包含在標題中。我也把它放在兩個文件中。 – user2089851 2013-02-21 03:30:33

6

我有一個類似的問題,並通過刪除標題旁邊生成的[標題名稱] .gch文件解決了這個問題,並且該文件顯然已被破壞。也許你可以嘗試嗎?

+3

+1:這是第一件要檢查的事情,最後經常這樣做,以至於它不好笑......(好吧,好吧,或許這有點兒有趣) – 2015-07-04 19:36:15

相關問題