function obj example
unknown
c_cpp
a year ago
693 B
6
Indexable
#include <iostream> #include <math.h> class SIN { private: double important_var; const double degmul = 180 / (2 * M_PI); public: enum Mode { rad, deg }; Mode mo; SIN(Mode m) : mo(m){}; double operator()(double a) { switch (mo) { case Mode::rad: important_var=1; return sin(a); case Mode::deg: important_var=2; return sin(a * degmul); default: return 0; } } }; int main() { SIN sinR(SIN::Mode::rad); SIN sinD(SIN::Mode::deg); std::cout << sinR(M_PI) << std::endl; std::cout << sinD(M_PI); return 0; }
Editor is loading...
Leave a Comment