C++ custom type literal constant

int i = 888;

The compiler will convert the number 888 into an int object. You can also do this for custom types:

#define debug qDebug()<<
struct ceshi
{
    int frist;
    int second;
    ceshi(int one = 0,int two = 0):frist{one},second{two}
    {
    }
};
ceshi operator"" _xxx(long double f)
{
    return ceshi(f,88);
}

int main(int argc, char *argv[])
{
    ceshi f = 44.4_xxx;
    debug f.frist << f.second;
}

The symbol beginning with an underscore after the operator "" is used as a custom type literal constant operator. Must start with an underscore, and those that do not start with an underscore are reserved for use in the standard library and support the following types of parameters:

operator "" identifier (const char *);
operator "" identifier (unsigned long long int);
operator "" identifier (long double);
operator "" identifier (char);
operator "" identifier (const char*, std::size_t);

Guess you like

Origin blog.csdn.net/kenfan1647/article/details/114443456
Recommended