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  |
 |
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
|
|
|
|
|
Goto Forum:
Current Time: Tue May 13 14:17:09 CEST 2025
Total time taken to generate the page: 0.00615 seconds
|