function obj example

mail@pastecode.io avatar
unknown
c_cpp
13 days ago
693 B
4
Indexable
Never
#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;
}
Leave a Comment