gogolf0401
gogolf0401

Reputation: 93

No matching function for call to unresolved overloaded function type

I am getting an error which I don't understand. I'm sure it is quite simple.. but I am still learning C++. I'm not sure if it is related to my parameters being exactly the same for the pure virtual function declaration or if it is something else.

Here is my simplified code:

in header_A.h

class HandlerType
{
public:
   virtual void Rxmsg(same parameters) = 0; //pure virtual
};

--------------------------------------------------
in header_B.h

class mine : public HandlerType
{
public:
   virtual void myinit();
   void Rxmsg(same parameters); // here I have the same parameter list 
//except I have to fully qualify the types since I'm not in the same namespace
};

--------------------------------------------------
in header_C.h

class localnode
{
public:
virtual bool RegisterHandler(int n, HandlerType & handler);
};
--------------------------------------------------

in B.cpp

using mine;

void mine::myinit()
{
   RegisterHandler(123, Rxmsg); //this is where I am getting the error
}

void Rxmsg(same parameters)
{
   do something;
}

Upvotes: 2

Views: 2017

Answers (2)

gogolf0401
gogolf0401

Reputation: 93

Changing RegisterHandler(123, Rxmsg); to RegisterHandler(123, *this); Solved the problem. Thanks!

Upvotes: 1

Jakob Riedle
Jakob Riedle

Reputation: 2018

It seems to me, that bool RegisterHandler(int n, HandlerType & handler) takes a reference to an object of the class HandlerType and you're trying to pass a function. Obviously that doesn't work.

So I think what you wanna do is passing *this instead of Rxmsg. This will supply RegisterHandler with an instance of the class mine, on which the overridden function Rxmsg can now be invoked.

Notice that the Function Rxmsg will, if done that way, be called on the exact same Object that the variable *this had, at the moment you supplied it to RegisterHandler.

I hope this is what you intended to do and I hope I could help you.

Upvotes: 2

Related Questions