Developing a custom type user-defined-literal - C++ Class

C++ examples for Class:Custom Literal

Description

Developing a custom type user-defined-literal

Demo Code

#include <iostream>

using namespace std;

struct MyType// www .  j av  a 2  s .com
{
    MyType (double Input):Value(Input){}
    double Value;
};

MyType operator"" _mytype (long double Value)
{
    return MyType(Value);
}

int main()
{
    auto UDLType = 145.6_mytype;

    cout << UDLType.Value << endl;

    return 0;
}

Result


Related Tutorials