C++ Templates type casting with derivates

后端 未结 4 1409
离开以前
离开以前 2021-01-18 10:10

I\'m trying to cast from one generic to another, say:

myClass anItem = myclass anotherObject;
         


        
4条回答
  •  南方客
    南方客 (楼主)
    2021-01-18 11:01

    Sorry, that is not possible. (Well, unless you do nasty reinterpret_cast hacks, but you don't want to do that - the end result would not be pretty).

    T and T are not related. Compiler cannot assume that - remember that it is entirely possible that T was specialized for Derived to be something completely different.

提交回复
热议问题