編譯基本類和頭時出現此錯誤。不知道我是否錯過了明顯的東西?如果需要可以提供任何額外的細節。沒有在類中聲明成員函數 - 編譯出錯時
注意:我在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
我確實包括它,我仍然得到相同的錯誤。 – user2089851 2013-02-21 03:23:11
你把它包含在錯誤的地方,將它包含在Event.h文件中,而不是Event.cpp – billz 2013-02-21 03:25:54
我明確地將它包含在標題中。我也把它放在兩個文件中。 – user2089851 2013-02-21 03:30:33