简体   繁体   中英

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. All the methods are static .

In my class 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:

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

The call of sendMessage seems to be static access, but the method is not declated static. Either the medthod should be declared static or an instance of ``MessageQueue is needed; see here for an explanation of static member functions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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