But I couldn't find an example in their code of how this is used. I understand it's going to return the current "Color" converted to an "SDL_Color" object, but some clarification on any of these would be awesome:
What is the main purpose of declaring it as an operator?
How would it be called? (it's behind the color class scope, right? Or did the operator keyword override that?)
Or is it more like a static member function now?
How does it return a value without an explicit return type?
What is the correct term for what they are doing?
that SDL is a *cast operator*. https://en.cppreference.com/w/cpp/language/cast_operator
so you will see it either in C style casts (SDL_COLOR)variable or c++ casts static_cast<SDL_Color>(variable) or something like this. It MAY also be used in assignments, or parameter passing, eg foo(variable) may be smart enough to convert it if foo takes an SDL color type, and so on.
Its an operator because that is how casting works with your objects. Casting is referred to as using a cast operation and cast operators, but people don't really think of them like that unless reading a textbook or jargoned up piece.
Cast overloads can give trouble, there are times when you might want to just use the variable with an implicit casting and the C++ won't work until it is cast into the other thing explicitly. Cout is really funky about this, in my experience. Its probably good practice, if you define this operator, to explicitly cast it wherever you use it to the type you want, if there is ANY potential at all it could cast to the other type behind your back. Others may have some tips on controlling that safely; I try not to use them very often.
Thank you guys,
I've already got a couple of situations that I could use this for, had no idea it was available.
I'm immediately getting the google results I needed; thank you Jonnin for the terminology so I can look deeper into it and for the advisory warning as well.