Wednesday, 23 January 2019

Why should you not overload the casting operators

Why should you not overload the casting operators? What should you use instead? Why?

Answer:


By defining casting operators you let C++ automatically change the type of a class to
something else when needed. The trouble is that C++ may do this when you don’t want it
done.
You can define an ordinary member function to do the conversion. Then you can
explicitly control the conversion.

No comments:

Post a Comment