example4_functors.cpp

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
#include <iostream>
#include <functional>

class Divider {
public:
    double operator()(double a, double b) const {
        return a / b;
    }
};

int main() {
    std::function<double(double, double)> func = Divider();
    
    std::cout << "Result: " << func(10.0, 2.0) << std::endl;
    return 0;
}
Back to std_function