[Dune] passing functions as arguments

Aleksejs Fomins aleksejs.fomins at lspr.ch
Mon Aug 18 09:24:55 CEST 2014


Hi Christian,
Thank you for your reply.

I think I understand now. I was not aware of duck-typing, so I thought
that everything should be done using inheritance which would not really
work. I previously omitted the template parameters to shorten the
snippet, but perhaps that was too much shortening :)

Have a nice day,
Aleksejs



On 08/15/2014 11:15 PM, Christian Engwer wrote:
> Sorry, but I don't understand what you are trying to ask.
> 
> but some comments regarding your code snippet.
> 
>> Very briefly, what I am trying to do is something like this:
>>
>> ------------------------------------------------------
>>
>> class f1 : Dune::Function  { // Define f1.evaluate }
>                         ^^^^^
> what happend to the template parameters?
> 
>> class f2 : Dune::Function  { // Define f2.evaluate }
>> class f3 : Dune::Function  { // Define f3.evaluate }
>>
>>
>> double integral( Dune::Function g)
>> {
>>    return g.evaluate(3) + g.evaluate(5) + g.evaluate(7);
>> }
>>
>> int main()
>> {
>>    cout << integral(f1) << integral(f2) << integral(f3);
>> }
>>
>> ------------------------------------------------------
>>
>>
>> I have a suspicion that if I write it this way, the generic evaluate
>> method from Dune::Function will be called inside the integral function.
> 
> which generic evaluate method? There is only a prototype for evaluate
> in Dune::Function, but no implementation. The whole class work via
> duck-typing.
> 
> Everything works the same way as with stl functors, just that we
> expect a different interface... http://www.sgi.com/tech/stl/functors.html
> A Dune::Function is basically the same as an stl::unary_function, but
> instead of overloading the () operator we have a method evaluate.
> 
> I hope this helps, but I'm really puzzled by your question.
> 
> Ciao
> Christian
> 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 551 bytes
Desc: OpenPGP digital signature
URL: <https://lists.dune-project.org/pipermail/dune/attachments/20140818/23a95f62/attachment.sig>


More information about the Dune mailing list