简体   繁体   English

C ++:无法在没有对象的情况下调用成员函数

[英]C++: cannot call member function without object

I have a class nammed MessageQueue, with 2 methods (one template, and one normal) with a different signature, but with the same name. 我有一个类nammed MessageQueue,有两个方法(一个模板,一个普通),具有不同的签名,但具有相同的名称。 All the methods are static . 所有方法都是静态的

In my class MessageQueue (MessageQueue.h): 在我的类MessageQueue(MessageQueue.h)中:

template <class T> void MessageQueue::sendMessage(const ___handle queue,
                                              const MESSAGE_ACTION &action,
                                              const T *pMessage)
{
    sendMessage(queue, action, (void*)pMessage, sizeof(pMessage));
}

In MessageQueue.cpp: 在MessageQueue.cpp中:

void MessageQueue::sendMessage(const ___handle queue, const MESSAGE_ACTION &action,
                           const void *pMessage, const ___uint16 &size)
{
  // ...
}

I have a compilation error on this line: 我在这一行有一个编译错误:

sendMessage(queue, action, (void*)pMessage, sizeof(pMessage));

The error is: 错误是:

error: cannot call member function 'void MessageQueue::sendMessage(void*, const MESSAGE_ACTION&, const void*, const ___uint16&)' without object 错误:无法调用成员函数'void MessageQueue :: sendMessage(void *,const MESSAGE_ACTION&,const void *,const ___ uint16&)'没有对象

The call of sendMessage seems to be static access, but the method is not declated static. sendMessage的调用似乎是静态访问,但该方法不是静态的。 Either the medthod should be declared static or an instance of ``MessageQueue is needed; 要么将方法声明为静态,要么需要“MessageQueue”的实例; see here for an explanation of static member functions. 请参阅此处以获取静态成员函数的说明。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM