I'm getting this error:

error: no matching function for call to 'cp::cpImageButton::SetMouseClickCallback(TitleScreen* const, void (TitleScreen::*)())'|

note: candidates are: void cp::cpImageButton::SetMouseClickCallback(DisplayObjectContainer*, void (DisplayObjectContainer::*)())|

However, TitleScreen inherits from DisplayObjectContainer, so I'm unsure why this isn't working. I haven't really worked with inheritance in C++ much, so a push in the right direction would be appreciated.

I have a suspicion about your issue, but I have a question first.

What does the cp::cpImageButton::SetMouseClickCallback method do? Does it modify the DisplayObjectContainer object?

It just stores the two pointers given to it in member variables for use later.

The member variables are members of which object? The object pointed by the first argument or some other object.

I ask because I think the const on your first argument is part of the issue. It doesn't seem like it should be, it's making the pointer const, not the object itself.

Is cp::cpImageButton::SetMouseClickCallback a method you wrote or part of someone else's library? Also, how many overloaded versions of it are there? There must be more than one version, the error you are reporting generally is indicative of an ambiguous function call...

The cp::cpImageButton::SetMouseClickCallback method stores the two pointers that are sent to it in member variables of the cpImageButton object. The interface looks like this:

void SetMouseClickCallback(DisplayObjectContainer * container, void (DisplayObjectContainer::*callback)());

The library is an extension for another set of libraries I'm using written by someone else but it lacked a lot so I've added a considerable amount to it myself (including this function). There are no overloaded versions.

Since it's your code, try adding const to the declaration of the first parameter. This will protect the pointer to the argument object from being modified. (Note: this will not protect the object itself, just the pointer to the object.)

void SetMouseClickCallback(DisplayObjectContainer * [B]const[/B] container, void (DisplayObjectContainer::*callback)());

Getting the same error:

error: no matching function for call to 'cp::cpImageButton::SetMouseClickCallback(TitleScreen* const, void (TitleScreen::*)())'|

note: candidates are: void cp::cpImageButton::SetMouseClickCallback(DisplayObjectContainer*, void (DisplayObjectContainer::*)())|

If it helps, this is how I'm calling it:

ExitButton->SetMouseClickCallback(this, &TitleScreen::CloseClient);

I did a test and temporarily removed the second parameter, and as suspected, it turns out that the second parameter (the method pointer) is the problem. Can't think of a workaround though.

When you declare the TitleScreen pointer, do you declare it as

TitleScreen *pTS = new TitleScreen;

or as

DisplayObjectContainer *pDOC = new TitleScreen;

???

If you did it the first way, that may explain the incompatibility. If you did it the second way, I'm not sure what the issue is.

EDIT (didn't see second post in time):
Function pointers are something I am not good with. If that is the issue, I'm going to have to respectfully bow out. Hopefully, someone else will be able to help you.

Yeah that wasn't the problem either. I decided to go a completely different route and changed the whole structure of my event system and it's working fine now. Would still be good to know how to do such a thing (if possible) for future reference though.

This page might help, but I'm sure it's the first you found in researching this issue.

I know why the error happens. "this" and "this" are different. Let me explain. The this pointer you pass to the function is of type TitleScreen* but can be implicitly casted up to a DisplayObjectContainer* (as a base class of TitleScreen). The problem is once transformed into DisplayObjectContainer* it might not point exactly to the same address in memory (this is related to the support for multiple inheritance). This means that if you were to pass the "this" that was casted to DisplayObjectContainer* to a pointer-to-member-function of the class TitleScreen, once inside that method, the this pointer might be offset and thus invalid. This is why C++ will not allow you to pass a pointer-to-member-function that is not directly from DisplayObjectContainer class or one of its base.

So simply put, if the function you are calling says (DisplayObjectContainer::*), then you have to call it with &DisplayObjectContainer::..something..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.