Container covariance in C++

前端 未结 4 1059
清酒与你
清酒与你 2020-12-06 00:10

I know that C++ doesn\'t support covariance for containers elements, as in Java or C#. So the following code probably is undefined behavior:

#include 

        
4条回答
  •  醉酒成梦
    2020-12-06 00:48

    You are invoking the bad spirit of reinterpret_cast<>.

    Unless you really know what you do (I mean not proudly and not pedantically) reinterpret_cast is one of the gates of evil.

    The only safe use I know of is managing classes and structures between C++ and C functions calls. There maybe some others however.

提交回复
热议问题