[Dune] passing functions as arguments

Christian Engwer christian.engwer at uni-muenster.de
Fri Aug 15 23:15:47 CEST 2014


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




More information about the Dune mailing list