How to generate a compiler warning/error when object sliced

后端 未结 8 1572
执笔经年
执笔经年 2021-02-04 03:58

I want to know if it is possible to let compiler issue a warning/error for code as following:

Note:

1. Yea, it is bad programming style and

8条回答
  •  一整个雨季
    2021-02-04 04:05

    This is commonly called Object Slicing and is a well-known enough problem to have its own Wikipedia article (although it is only a short description of the problem).

    I believe I have used a compiler that had a warning you could enable to detect and warn about this. However, I don't recall which one that was.

提交回复
热议问题