Using C++ style typecastings (all 4) look exactly like some function template. e.g.
template
TO dynamic_cast (
Pointer conversion with dynamic_cast
, reinterpret_cast
and static_cast
have well defined meanings and it is probably better not to allow overloading.
It would be a pain to allow users to change the meaning of const_cast
.
Only object type casting remains.
struct A
{
A() {};
template
A(FROM&) {
std::cout << "Casting to A \\o/" << std::endl;
}
template
operator TO() {
std::cout << "Casting from A \\o/" << std::endl;
return TO();
}
};
then
int i; A a;
A toA = static_cast(i); // Casting to A \o/
int fromA = static_cast(a); // Casting from A \o/
Hopefully you have better use cases than mine :)