Skip to content

Better example for function objects #399

@bernhardmgruber

Description

@bernhardmgruber

Our current example for function objects is:

    struct BinaryFunction {
      virtual double operator() (double a, double b) = 0;
    };
    double binary_op(double a, double b, BinaryFunction &func) {
      return func(a, b);
    }
    struct Add : BinaryFunction {
      double operator() (double a, double b) override
      { return a+b; }
    };
    Add addfunc;
    double c = binary_op(a, b, addfunc);

which I think is really bad, since function objects are used with templates since the beginning of the STL. Furthermore, I don't want to encourage the use of inheritance for function objects. We should come up with a better slide here.

Metadata

Metadata

Labels

EssentialsContent for the "essentials" course

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions