ms*****@mail.com (mshetty) wrote in message news:<bf**************************@posting.google. com>...
Hi,
I get an error "Warning: b::a_method hides the virtual function
a::a_method()."
on compiling the following code..
[snip]
The warning goes off if done the following:
Change class b : public a
to
class b : public virtual a
Have not been to understand the reason why the warning is removed as
"b::a_method still hides a::a_method()"
As others have pointed out, b::a_method() does hide a::a_method(), and
it seems it should hide it whether "a" is a virtual base of "b" or
not.
Intrigued by this, I tried your code under both GCC 3.4.1 and Sun CC
5.3 (WorkShop 6 Update 2) on Solaris 8, and was astonished by the
results:
`g++ -Wall -ansi -pedantic` compiled both the virtual and nonvirtual
versions without so much as a single warning (after changing
iostream.h to iostream and adding "using std::cout" and "using
std::endl" at the top). I tried this multiple times out of disbelief,
but the result was indeed the same each time; no mistyping on my part.
`CC +w2` produced the following results:
--BEGIN--
# CC +w2 virtual_base.cxx
"virtual_base.cxx", line 25: Warning: b::a_method hides the virtual
function a::a_method().
1 Warning(s) detected.
# vim virtual_base.cxx
[change base to virtual]
# CC +w2 virtual_base.cxx
"virtual_base.cxx", line 25: Warning: b::a_method Hides the virtual
function a::a_method() in a virtual base.
1 Warning(s) detected.
--END--
So now I'm even more confused. The Sun compiler seems to be right on
with this one, and GCC is oblivious, which is exactly backwards from
what I might've expected. What compiler and platform are you using,
M? Can anyone else provide some insight into what's going on?
Mike
[ See
http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]