c++ - Custom literal works with long double but not double, and with pass by value but not pass by reference -
I'm experimenting with C ++ custom literals. I find it strange that when I change type from Is it well thought out that the specifics in the design of language, or just that the specifics that can not deal with my compiler (GCC 4.8.2)? C ++ standard, section § 13.5.8 (user-defined litrils) , Lists all valid types: The announcement of a literal operator will be a parameter-declaration-clause equal to one of the following: neither long double type to
double , or when trying to pass from context, then working the normal function below First of all I thought that it had to be done with the use of
constexpr but it does not seem that these two works are right because it is not on the code. Operator "" , and
constexpr to remove from
operator "" not error Removes.
// conversion function, both long double and double / double, and without reference with or without Constexpr long double to_deg (const long double and degree) {return degree * M_PI / 180.0 ; } // long pass with double passwords, literally and with value, // work fine Constexpr long double operator "" _deg (long double degree) {return degree * M_PI / 180.0; } // Supports custom literal, "invalid argument list" with double types. // Error Constexpr double operator "" _deg (double degree) {return degree * M_PI / 180.0; } // Returns the custom verbally, "invalid argument list" with reference from near. // Error does not remove delete error Constexpr long double operator "" _deg (constant long double and degree) {return degree * M_PI / 180.0; }
double or
double & amp; ,
Constant Long Double & amp; are listed here: so they do not have permission.
Comments
Post a Comment