You are here:

C++/overloaded function



I compiled the below code in CC and get:
'Warning: b::a_method hides the virtual function a::a_method().'

class a
 virtual int a_method(int x, int y, int z)
 virtual int a_method(int x, int y)

class b : public a
 int a_method(int x, int y)
  int temp;
  return a::a_method(x, y, z); //

When we declare an overloaded function in derived class (b::a_method(int)) it hides all functions with the same name from base class (a::a_method()). But in our code using a::a_method in b definition, a::a_method won't become hidden. My question is that is there anything we can do to get rid of the warnings? Or is it compiler's issues and nothing we can do?  


I tried this with my C++ compiler (Visual Studio 2002) and I don't get a warning with the code above.  Do you get the warning with exactly the code above?  If not, maybe something was deleted and got rid of it.  I did get an error about 'z' so I just made it a 1.

If your tools are older, it might be a bug.  If they are very current then perhaps it's a new warning that Visual Studio is missing.  To me it sounds like a picky warning anyway and I wouldn't worry about it.



All Answers

Answers by Expert:

Ask Experts


Bill A


I can answer questions about C++, programming algorithms, Windows programming in MFC (which is C++). I cannot answer questions about STL (templates) and I have no experience with Linux. I do enjoy reviewing code and critiquing it or finding problems in it. I will also gladly show better algorithms or methods if you want to take advantage of that.


I've developed a commercial embedded C compiler/assembler and IDE with debugger toolset, of which the IDE and debugger are written in C++. I work in the industry writing high tech embedded programs and Windows programs to communicate with the embedded devices.

Book: Embedded Systems Design using the Rabbit 3000 Microprocessor Authored Chapter 10 in its entirety.

BS Computer Engineering

©2016 All rights reserved.