I have a class called IAckHandler
class IAckHandler {
public:
virtual ~IAckHandler();
virtual void handleAck(long messageType, bool ackrcvd, uint8_t ackByte) = 0;
private:
};
The intended use is for other classes to inherit, so this is basically a “interface” class.
I am using message queues to submit requests to a polling thread(uart comm) and want to pass in an IAckHandler into the message queue message.
The struct is like so:
struct reqmsg
{
long int mtype;
void (*reqHandler)(MasterRadioComm*, uint8_t*);
IAckHandler* ackHandler;
unsigned char mtext[NUM_INDICES];
};
Here is the function to submit to message queue
void Uartcom::req_doSomething(IAckHandler& ackHandler)
{
struct reqmsg req;
if(ackHandler == NULL) req.ackHandler = this;
else req.ackHandler = ackHandler;
msgsnd(m_msgQueueKey, &req, sizeof(struct reqmsg) - sizeof(long), 0);
}
But when I pass in a reference to an IAckHandler, I get cannot convert ‘IAckHandler’ to ‘IAckHandler*’ in assignment.
Can I call req_doSomething(this) from another class that inherits IAckHandler?
You seem to be lacking some basic pointers and references knowledge. For the
req_doSomethinggiven in the example,&refwill give you a pointer to the referred object so it should beand to get a reference from a pointer, you derreference it with
*ptrso the call would be…or just drop the reference and work entirely with pointers.
Update: As others have pointed out, a reference cannot be NULL.