没有在类中声明的成员函数 - 基本编译时出错

use*_*851 3 c++ compiler-errors header

编译基本类和标题时出现此错误.不确定我是否遗漏了明显的东西?如果需要,可以提供任何其他细节.

注意:我#include <string>在Event.h中添加了错误,但错误仍然存​​在.

Event.cpp

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

std::string Event::getLabel() {
    return label;
}
Run Code Online (Sandbox Code Playgroud)

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
Run Code Online (Sandbox Code Playgroud)

编译和错误

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
Run Code Online (Sandbox Code Playgroud)

Lud*_*wik 9

我有一个类似的问题,并通过删除标题旁边生成的[标题名称] .gch文件解决了它,显然已经损坏了.也许你可以尝试一下?

  • +1:这是第一件要检查的事情,并且最终经常工作以至于它不好笑......(好吧,好吧,也许它有点*有点搞笑) (3认同)