vendredi 27 septembre 2019

Using user defined literals at run runtime

I am trying to use user defined literals at runtime.

Instead of hard coding the literal at compile time, I would like to specify the value at runtime.

I created this, but now cannot progress.

#include <cmath>
#include <iostream>

class Degrees
{
    double degree_;

public:

    explicit Degrees(long double degree) : degree_(degree) {}

    double GetValue() const { return degree_; };
};

Degrees operator "" _deg(long double degree)
{
    // Returns radians
    return Degrees(degree * 3.14159265358979323846264L / 180);
}

int main(int argc, const char * argv[])
{
    long double angle;
    std::cin >> angle;

    Degrees degrees(angle);

    //degrees = 3.1_deg;

    std::cout << degrees.GetValue() << "\n";
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire