5

I recently watched GoingNative2012 about, of course, C++11.

In Bjarne Stroustrup section, I found out there was an interesting operator function, which was as belows.

constexpr Value<Second> operator""s(long double d) { return Value<Second>(d); } 

Well, beside constexpr that looks like a new keyword in C++11,

I've never known "" is overload-able?

Is this one of the new features in C++ although I failed to test it using VS 2010?

Thanks in advance.

2
  • 5
    Were you not listening to what he was saying when you watched it? Commented Apr 7, 2012 at 9:11
  • 1
    This code sample is incorrect in two ways: 1) whitespace is required between the "" and the suffix, and 2) user-defined suffixes should start with an underscore; suffixes not starting with an underscore are reserved for future standardization. Commented Apr 9, 2012 at 3:12

1 Answer 1

5

It is a new C++11 core language feature: user defined litterals

Sign up to request clarification or add additional context in comments.

8 Comments

Take care though that as that article is on Wikipedia, it just might not be entirely formally correct. (For instance, where it says “The characters "12.5" are a literal that is resolved by the compiler as a type double with the value of 12.5.”...)
Agreed that some details on Wikipedia may be slightly wrong, but it is a good and easy to understand summary of what the C++11 standard (nearly a thousand difficult pages to read) brings....
Here's a link to the section in the official C++11 FAQ: www2.research.att.com/~bs/C++0xFAQ.html#UD-literals
@MrLister: So, are the characters "12.5" not in fact a literal that is of type double? If not, then what are they?
@MrLister: I'm not twisting your words; that's what you said. You stated that the Wiki article is wrong because The characters "12.5" are a string literal, not a double. I'm saying that it depends on how you interpret the " marks. In English, quotes mean "exactly everything between these." In C++, quotes mean "string literal". So the article is correct, depending on how you look at it.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.