What does this do, and what is this called? I've never seen this before:
operator double() { return x; }
It is operator overloading.
You are probably familiar with things overloading operators like operator+ or operator>>
You can overload many other operators.
That one is a conversion operator. You can provide custom conversions to things like doubles and floats, shorts and longs, and other types.
There are many infrequently overloaded operators out there. The function call operator, or operator(), is an interesting one used for fun effect. Some people are more familiar with that by making things called "functors" or "function objects", overloading operator() so you can call the function operation on an object. The memory management operators( new, new[], delete, delete[] ) can be overloaded, and that one is usually mentioned in books.
The comma operator or operator, can be overloaded, but since it has weird precedence it can make weird things happen and people don't tend to use it.
Smart pointers tend to overload operator&, operator*, and operator->, so you might be familiar with those. The member reference operators of operator-> and operator->* are sometimes overloaded as a pair which can do creepy but wonderful things if you are implementing a proxy object.
The subscript or array operator[] can be overloaded, which many people have used as a notation for n-dimensional arrays. Since you can overload the parameters as well, you can add two, three, four, or however many you want. That leads to things like bar=foo[x,y,true]; which can freak some people out.
Relatively new is operator"" or the literal operator and it has some potentially odd effects that people are still playing with, especially when it comes to templates. The literal operator lets you create your own custom suffixes, and the standard gives this example to help you understand it:
[Example:
long double operator "" _w(long double);
std::string operator "" _w(const char16_t*, std::size_t);
unsigned operator "" _w(const char*);
int main() {
1.2_w; // calls operator "" _w(1.2L)
u"one"_w; // calls operator "" _w(u"one", 3)
12_w; // calls operator "" _w("12")
"two"_w; // error: no applicable literal operator
}
— end example ]
The only operators left out of the party are the member selection operators dot (.) and dot star (.*) which are needed to guarantee you can access the real item somehow, the scope resolution operator ( :: ) for hopefully obvious reasons, the conditional operator ( ?: ) for reasons covered in the discussion already, and the sizeof and typeid operators because those could cause even worse havoc if they were customized. But everything else can be customized with whatever you need.