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 » Community » Newbie corner » Callbacks mechanism doesn't handle overloaded functions?
Callbacks mechanism doesn't handle overloaded functions? [message #37475] Wed, 10 October 2012 21:05 Go to next message
Peter is currently offline  Peter
Messages: 16
Registered: October 2012
Promising Member
Hi.

I'm a new U++ user with little experience, especially in how the framework important features work internally. That's why I'm not sure if I discovered a bug or merely a framework limitation. Here's a code snippet to demonstrate the problem:

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

class MyWindow : public TopWindow
{
	Button btn;
	
	void Fun() {PromptOK(AsString(5));}
	void Fun(int n){PromptOK(AsString(n));}
	
	public:
	typedef MyWindow CLASSNAME;
	MyWindow()
	{
		btn <<= THISBACK(Fun);
	}
};

GUI_APP_MAIN
{
	MyWindow().Run();
}


In the code above you can see two different, overloaded functions named Fun. When I try to compile it, compiler reports the following error:

error C2668: 'Upp::callback' : ambiguous call to overloaded function

Surprisingly, if I change the following line:

btn <<= THISBACK(Fun); //reference to void Fun()


to:

btn <<= THISBACK1(Fun, 1); // reference to void Fun(int)


the code compiles fine.

What causes the error in the first case? I don't see any ambiguity here since void Fun() and void Fun(int) are two distinct functions and THISBACK macro should most likely treat them as such. Is it a design/implementation oversight or rather a natural consequence of how the callback mechanism internally works and callbacks simply don't work with overloaded functions the way one would expect? If the latter is the case, however, how come there's no ambiguity in the second case?

Peter
Re: Callbacks mechanism doesn't handle overloaded functions? [message #37484 is a reply to message #37475] Wed, 10 October 2012 21:50 Go to previous message
mirek is currently offline  mirek
Messages: 13975
Registered: November 2005
Ultimate Member
Peter wrote on Wed, 10 October 2012 15:05

Hi.

I'm a new U++ user with little experience, especially in how the framework important features work internally. That's why I'm not sure if I discovered a bug or merely a framework limitation. Here's a code snippet to demonstrate the problem:

#include <CtrlLib/CtrlLib.h>

using namespace Upp;

class MyWindow : public TopWindow
{
	Button btn;
	
	void Fun() {PromptOK(AsString(5));}
	void Fun(int n){PromptOK(AsString(n));}
	
	public:
	typedef MyWindow CLASSNAME;
	MyWindow()
	{
		btn <<= THISBACK(Fun);
	}
};

GUI_APP_MAIN
{
	MyWindow().Run();
}


In the code above you can see two different, overloaded functions named Fun. When I try to compile it, compiler reports the following error:

error C2668: 'Upp::callback' : ambiguous call to overloaded function



Well, while it is clear that btn.WhenAction is no-parameter Callback, THISBACK(Fun) is evaluated (by compiler) independently of this fact. As such, it is indeed ambiguous whether you mean Callback with no parameters or with single parameter at this point.

Unfortunately, there is no nice solution here (C++ language limitation). You have to name your methods differently...

Mirek
Previous Topic: Need help at Linux (debian) install
Next Topic: ArrayCtrl - convert String
Goto Forum:
  


Current Time: Sun Apr 28 03:00:13 CEST 2024

Total time taken to generate the page: 0.07003 seconds