Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 类中未声明成员函数-基本编译错误_C++_Header_Compiler Errors - Fatal编程技术网

C++ 类中未声明成员函数-基本编译错误

C++ 类中未声明成员函数-基本编译错误,c++,header,compiler-errors,C++,Header,Compiler Errors,编译基本类和标头时出现此错误。不确定我是否遗漏了一些明显的东西?如果需要,可以提供任何其他详细信息 注意:我在Event.h中添加了#include,错误仍然存在 Event.cpp #include "Event.h" #include <string> std::string Event::getLabel() { return label; } 编译错误 g++ -c -Wall -pedantic correngine.cpp g++ -c -Wall -peda

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

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

Event.cpp

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

std::string Event::getLabel() {
    return label;
}
编译错误

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

您需要在Event.h中包含
std::string
标题

#ifndef EVENT_H
#define EVENT_H

#include <string>        //<<----  here

#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
\ifndef事件
#定义事件

#include/我遇到了一个类似的问题,通过删除头旁边生成的[header name].gch文件解决了这个问题,该文件显然已损坏。也许你可以试试看?

你把它放错地方了,把它放在Event.h文件中而不是Event.cppI肯定把它放在了标题中。我也把它放在这两个文件中。这很有趣,我用
#include
编译了您的代码,然后错误消息在我的环境中消失了。如果包含必要的头,我看不出它失败的任何原因。我将类型更改为int,并且出现了相同的错误(将int替换为std::string),因此这不是问题所在。@user2089851:我猜范围中还有另一个不相关的
事件
类使编译器感到困惑。尝试将类的名称更改为其他名称。如果错误仍然存在,那么就会发生一些不正常的事情。+1:这是第一件要检查的事情,结果工作得太频繁了,这一点都不好笑。。。(好吧,也许有点滑稽)有趣。有没有一种方法可以在不手动删除文件的情况下执行此操作?就像某些IDE-s或编译器中的
clean
rebuild
选项一样,这些选项会丢弃所有临时或中间文件并重新开始,正是为了解决此类问题。
#ifndef EVENT_H
#define EVENT_H

#include <string>        //<<----  here

#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