gpt4 book ai didi

c++ - 类中没有声明成员函数 - 基本编译错误

转载 作者:太空狗 更新时间:2023-10-29 19:44:05 24 4
gpt4 key购买 nike

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

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

事件.cpp

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

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

事件.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

最佳答案

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

关于c++ - 类中没有声明成员函数 - 基本编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14993966/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com