Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site
Search in forums












SourceForge.net Logo
Home » Extra libraries, Code snippets, applications etc. » C++ language problems and code snippets » THISBACK and function-overloading
THISBACK and function-overloading [message #17024] Fri, 25 July 2008 11:29 Go to next message
michael is currently offline  michael
Messages: 153
Registered: May 2007
Location: Germany
Experienced Member
I'm using overloaded functions:

void ViewHistory()
{
  some code
}

void ViewHistory(String conditions)
{
  some other code
}

I'm calling this function by using THISBACK like this:

bar.Add("Aufwahlhistorie", ImgMainWnd::history(), THISBACK(ViewHistory)).Key(K_ALT_A).Help("Aufwahlhistorie").Enable(true);


Before i used overloading all went fine, since i'm using this overloaded function i got the following compile-error:

K:\Entwicklung\UPP\prohibisZA\prohibisZA.cpp(734) : error C2668: 'Upp::callback' : ambiguous call to overloaded function
        c:\upp\uppsrc\core\Cbgen.h(229): could be 'Upp::Callback1<P1> Upp::callback<prohibisZA,prohibisZA,Upp::String>(OBJECT *,void (__th
	iscall prohibisZA::* )(P1))'
        with
        [
            P1=Upp::String,
            OBJECT=prohibisZA
        ]
        c:\upp\uppsrc\core\Cbgen.h(80): or       'Upp::Callback Upp::callback<prohibisZA,prohibisZA>(OBJECT *,void (__thiscall prohibisZA:
	:* )(void))'
        with
        [
            OBJECT=prohibisZA
        ]
        while trying to match the argument list '(prohibisZA *const , overloaded-function)'
K:\Entwicklung\UPP\prohibisZA\prohibisZA.cpp(734) : error C2228: left of '.Key' must have class/struct/union
K:\Entwicklung\UPP\prohibisZA\prohibisZA.cpp(734) : error C2228: left of '.Help' must have class/struct/union
K:\Entwicklung\UPP\prohibisZA\prohibisZA.cpp(734) : error C2228: left of '.Enable' must have class/struct/union


How do i use THISBACK when using function-overloading?
Re: THISBACK and function-overloading [message #17025 is a reply to message #17024] Fri, 25 July 2008 11:49 Go to previous message
mrjt is currently offline  mrjt
Messages: 705
Registered: March 2007
Location: London
Contributor
I've had this problem, these are two solutions that I know of:
1) Obvious. Resolve the ambiguity by naming one of you functions something else.
2) Resolve the ambiguity caused by the compiler not being able to determine which version of the callback function to use. You could do this by casting the function pointer correctly, but this would be very ugly.

My prefered solution is to define callback0 somewhere (it's identical to callback, except for the name):
template <class OBJECT, class METHOD>
Callback callback0(OBJECT *object, void (METHOD::*method)()) {
	return callback(object, method);
}

template <class OBJECT, class METHOD>
Callback callback0(const OBJECT *object, void (METHOD::*method)() const) {
	return callback(object, method);
}

inline Callback callback0(void (*fn)()) {
	return callback(fn);
}
#define THISBACK0(x)               callback0(this, &CLASSNAME::x)
And then it is available to use for resolving this sort of ambiguity.
Perhaps there is a better solution available that I haven't thought of?

[Updated on: Fri, 25 July 2008 11:55]

Report message to a moderator

Previous Topic: What does , means?
Next Topic: STL multimap
Goto Forum:
  


Current Time: Fri Apr 26 06:22:25 CEST 2019

Total time taken to generate the page: 0.00984 seconds