How to abbreviate a function signature in C++

1 Answer

0 votes
#include <iostream>

// Abbreviation: alias for a function pointer type.
using MathFunc = double(*)(double);

// Example functions
double square(double x) { return x * x; }
double half(double x)   { return x / 2.0; }

int main() {
    MathFunc mf = square;  // Using the abbreviation
    std::cout << mf(8.0) << "\n";

    mf = half;
    std::cout << mf(8.0) << "\n";
}



/*
run:

64
4

*/

 



answered 1 day ago by avibootz
...