Is there any possibility to shorten this declaration as I use it very often in my code
For example, I use this to cast Object
to my CustomObject
using
dynamic_cast/static_cast<TCustomClassName*>(SenderObject)
Is there any possibility at all to shorten this using typedef static_cast<TCustomClassName*>
or something like this making sure it's possible using cast operator in typedef
?
No, you cannot, and you SHOULD NOT! Do not define any macros for the cast operators, it will confuse the maintainers of your application code, and will cause havoc in your programming circles. These operators are there exactly with the reason to offer a readable way of telling the programmer, that a cast is happening here. Casts regardless that are used on an everyday basis cause confusion between programmers, so these keywords are there to help them. So, stuck to them and use them wisely. Do not revert back even to C style casting, the purpose of these operators is to offer a way of understanding what happens in the code. If you are unfamiliar with them read this: When should static_cast, dynamic_cast, const_cast and reinterpret_cast be used?