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 » [SOLVED] Do Value can store anonymous function ?
[SOLVED] Do Value can store anonymous function ? [message #52765] Wed, 20 November 2019 13:55 Go to previous message
Xemuth is currently offline  Xemuth
Messages: 387
Registered: August 2018
Location: France
Senior Member
Hello community,

I'm wondering if value can store something like this :

#include <Core/Core.h>

using namespace Upp;

int testAddition(const int& a,const int& b){
	return a+b;	
}

CONSOLE_APP_MAIN
{
	int(*fn)(const int& ,const int&);
	fn = (int(*)(const int& ,const int&)) &testAddition;
	Cout() << fn(2,3) << EOL; //Working
	
	void* fn2 =(void*) fn;
	Cout() << ((int(*)(const int& ,const int&))fn2)(1,1) << EOL; //Working
	
	Value v = fn2;

	Cout() <<  static_cast<int(*)(const int& ,const int&)>( v.Get<void*>())(2,3) << EOL; //ambiguous conversion from Nuller to //Void*  & Invalide static_cast from void* to int(*)(const int&, const int&)
	Cout() << v.Get<Nuller>()(2,3) <<EOL; // no match for call to (const Upp::Nuller)(int,int) Logique....
	Cout() << ((int(*)(const int& ,const int&))v.Get<Nuller>())(2,3) <<EOL; //invalid cast
}


Using Value to store a ptr to function ?

Thanks in advance.

[Updated on: Wed, 20 November 2019 17:19]

Report message to a moderator

 
Read Message
Read Message
Read Message
Previous Topic: Segmentation Error, Assertion failed BiCont.h
Next Topic: [SOLVED] ERROR: Not in table (destructor clobbered?)
Goto Forum:
  


Current Time: Fri Mar 29 09:16:02 CET 2024

Total time taken to generate the page: 0.01409 seconds