Is it possible to determine the specialization of the static_cast (int) operator for converting from integers to class A
Not. static_cast is a keyword, not a template or function.
However, in your class A you can write a constructor that accepts int if you want this behavior.
struct A { A(int i) {} }; A a = 10;
Or, if you need some sort of syntactic sugar that should look like the cast, you can do this:
template<typename To, typename From> To type_cast(From from) { return To(from); }
then use it like:
A a = type_cast<A>(10);
But why do you have to do this? I see no advantage in this; therefore, I am preventing you from writing such a function template. I showed you this only for experimental and educational purposes. Such code should not be in real code.
source share