C++ generate a warning when a class member shadow a class member of its parent?

前端 未结 3 1146
灰色年华
灰色年华 2021-01-17 10:21

Is there a way to generate a warning when a derived class member variable name shadows one of its parents class, e.g

class Mother 
{
public:
  Mother() : i(0         


        
3条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-17 10:47

    This will not show a warning because this is allowed. It is possible because "at most one of the one of the names is actually defined in that scope; others would be merely visible in that scope. Name resolution rules determine which name is chosen, if there are multiple candidates...You really do not want to give a warning for every case where the compiler picks between alternatives." - @MSalters.

提交回复
热议问题