Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22271

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

$
0
0

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) {}
  virtual ~Mother() {}
protected:
  int i;
};

class Child : public Mother
{
public:
  Child() : Mother(), i(0) {}
  virtual ~Child() {}
protected:
  int i; /* NOK Expecting warning : declaration of 'int Child::i' shadows 'int Mother::i' */
};

Above code generates no warning when compiled with -Wshadow with g++.


Viewing all articles
Browse latest Browse all 22271

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>