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 » U++ Library support » U++ Callbacks and Timers » "Function" question
"Function" question [message #47714] Thu, 09 March 2017 14:19 Go to next message
koldo is currently online  koldo
Messages: 3354
Registered: August 2008
Senior Veteran
Hello all

I wanted to assign a Function from a subclass but compiler complains with error:

'&': illegal operation on bound member function expression

What have I to do?
class FuncSource {
protected:
	Function <double(double)> function;

public:
	FuncSource(Function <double(double)> function) : function(function) {}
	double f(double x)	{return function(x);}
};

class MySource : public FuncSource {
public:
	MySource(double data) : FuncSource(&Calc), data(data) {}  // COMPILER ERROR
	
	double Calc(double x) {return x + data/10;}
	
private:
	double data;
};


Best regards
Iñaki

[Updated on: Thu, 09 March 2017 14:19]

Report message to a moderator

Re: "Function" question [message #47715 is a reply to message #47714] Thu, 09 March 2017 17:52 Go to previous messageGo to next message
koldo is currently online  koldo
Messages: 3354
Registered: August 2008
Senior Veteran
Replacing

MySource(double data) : FuncSource(&Calc), data(data) {}  // COMPILER ERROR

with
MySource(double data) : FuncSource([=](double x) {return Calc(x);}), data(data) {}
it compiles, but at run time when Calc() have to be used, it has been destroyed.


Best regards
Iñaki
Re: "Function" question [message #47716 is a reply to message #47715] Thu, 09 March 2017 18:33 Go to previous message
koldo is currently online  koldo
Messages: 3354
Registered: August 2008
Senior Veteran
Well, it is solved
void Init(double data) {
	this->data = data;
	function = [=](double x) {return Calc(x);};
}

Now MySource is inside main model, so it does not get destroyed after initialization Rolling Eyes.


Best regards
Iñaki
Previous Topic: Event.execute
Next Topic: PostCallback in constructor
Goto Forum:
  


Current Time: Thu Mar 28 11:11:02 CET 2024

Total time taken to generate the page: 0.01332 seconds