类,错误:ISO C++禁止声明没有类型的"任务"
Classes, error: ISO C++ forbids declaration of 'Task' with no type
有人可以帮我理解我的错误吗?我对类的概念很陌生,不确定我错过了什么。我没有在头文件中正确声明任务* _task吗?谢谢。
MonReqServer.hh:18: error: ISO C++ forbids declaration of 'Task' with no type
MonReqServer.hh:18: error: expected ';' before '*' token
MonReqServer.cc: In constructor 'Pds::MonReqServer::MonReqServer()':
MonReqServer.cc:11: error: class 'Pds::MonReqServer' does not have any field named '_task'
MonReqServer.cc:13: error: '_task' was not declared in this scope
MonReqServer.cc: At global scope:
MonReqServer.cc:16: error: definition of implicitly-declared 'virtual Pds::MonReqServer::~MonReqServer()'
MonReqServer.cc: In destructor 'virtual Pds::MonReqServer::~MonReqServer()':
MonReqServer.cc:18: error: '_task' was not declared in this scope
MonReqServer.hh如下:
#ifndef Pds_MonReqServer_hh
#define Pds_MonReqServer_hh
#include "pds/utility/Appliance.hh"
#include "pds/service/Routine.hh"
namespace Pds {
class MonReqServer : public Appliance, public Routine {
public:
MonReqServer();
public:
Transition* transitions(Transition*);
InDatagram* events (InDatagram*);
void routine();
private:
Task* _task;
};
};
#endif
MonReqServer.cc 如下:
#include "pdsapp/tools/MonReqServer.hh"
#include "pds/service/Task.hh"
#define mult_address "225.0.0.37"
#define mult_port "1100"
using namespace Pds;
MonReqServer::MonReqServer() :
_task(new Task(TaskObject("monlisten")))
{
_task->call(this);
}
MonReqServer::~MonReqServer()
{
_task->destroy();
}
Transition* MonReqServer::transitions(Transition* tr)
{
printf("MonReqServer transition %sn",TransitionId::name(tr->id()));
return tr;
}
void MonReqServer::routine()
{
int udp_socket_info;
struct sockaddr_in udp_server;
struct sockaddr addr;
struct ip_mreq mreq;
socklen_t fromlen;
fromlen = sizeof addr;
char incoming_message[100];
udp_socket_info = socket(AF_INET, SOCK_DGRAM, 0);
if (udp_socket_info == -1) {
puts("Could not create socket");
}
memset((char*)&udp_server,0,sizeof(udp_server));
udp_server.sin_family=AF_INET;
udp_server.sin_port = htons( 1100 );
udp_server.sin_addr.s_addr = INADDR_ANY;
if (bind(udp_socket_info,(struct sockaddr *)&udp_server, sizeof(udp_server)) < 0) {
perror("bind error");
exit (1);
}
puts("bind");
//join multicast group
mreq.imr_multiaddr.s_addr=inet_addr(mult_address);
mreq.imr_interface.s_addr=htonl(INADDR_ANY);
if (setsockopt(udp_socket_info, IPPROTO_IP,IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0) {
perror("setsockopt");
exit (1);
}
if (recvfrom(udp_socket_info, incoming_message , sizeof(incoming_message), 0, &addr, &fromlen) <0) {
perror("recvfrom");
}
puts("Message received");
char tcp_ip[20];
char tcp_port[20];
sscanf( incoming_message, "%s %s", tcp_ip, tcp_port);
}
InDatagram* MonReqServer::events (InDatagram* dg)
{
(dg->seq.service()==TransitionId::L1Accept) {
}
return dg;
}
您可能需要更改MonReqServer.hh中#include
的顺序(我假设Task
是在Task.hh
中定义的(。但即便如此,在 MonReqServer.hh
中转发声明Task
也是一个好主意,以便包括MonReqServer.hh
在内的其他源文件知道Task
是一个类。也就是说,在引用Task
之前,将class Task;
放在MonReqServer.hh中。
的错误:这是因为您定义了析构函数而没有声明它。将~MonReqServer();
添加到头文件。
似乎标题
#include "pds/service/Task.hh"
包含 Task
声明的声明既没有显式也没有隐式包含在标题MonReqServer.hh
中,它用于类MonReqServer
class MonReqServer : public Appliance, public Routine {
public:
//...
private:
Task* _task;
^^^^^
};
由于编译器不知道Task
表示什么名称,因此它也忽略了变量_task
的声明。
此外,类定义不包含析构函数声明。但是,您在文件MonReqServer.cc
中定义了析构函数
MonReqServer::~MonReqServer()
{
_task->destroy();
}
相关文章:
- ArduinoJson 6.15.2:JsonObject没有命名类型
- 防止主数据类型C++的隐式转换
- 大量序列中核苷酸类型的快速计数
- 如何从C++中的依赖类型中获得它所依赖的类型
- 有关插入适配器的错误。[错误]请求从 'back_insert_iterator<vector<>>' 类型转换为非标量类型
- 是否可以初始化不可复制类型的成员变量(或基类)
- 如何获取std::result_of函数的返回类型
- 从父命名空间重载类型
- 如果C++类在类方法中具有动态分配,但没有构造函数/析构函数或任何非静态成员,那么它仍然是POD类型吗
- 我想将一个对T类型的非常量左值引用绑定到一个T类型的临时值
- Openssl 1.1.1d无效使用不完整的类型"struct dsa_st"
- 访问者访问变体并返回不同类型时出错
- 在VS2010-VS2015下编译时,如何使用decltype作为较大类型表达式的LHS
- 处理小于cpu数据总线的数据类型.(c++转换为机器代码)
- C++ 雷神库 - 使用资源加载器类时出现问题(不命名类型)
- 模板元程序查找相似的连续类型名称
- 是否可以从int转换为enum类类型
- c++中的任务列表(具有多个类型的向量)
- 类,错误:ISO C++禁止声明没有类型的"任务"
- PPL when_all不同类型的任务