This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/32934] No warning when creating a non const derived funtion from a const virtual funciton
- From: "pinskia at gcc dot gnu dot org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 30 Jul 2007 02:19:32 -0000
- Subject: [Bug c++/32934] No warning when creating a non const derived funtion from a const virtual funciton
- References: <bug-32934-14884@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- Comment #1 from pinskia at gcc dot gnu dot org 2007-07-30 02:19 -------
Well it is valid as B::print hides A::print.
Try doing:
#include <iostream>
class A {
public:
virtual char * print() const { return "A\n";}
virtual ~A(){};
};
class B : public A {
public:
virtual char * print() { return "B\n";}
using A::print;
virtual ~B(){};
};
int main ()
{
B b;
A & a = b;
const B &b1 = b;
std::cout << a.print() << b1.print();
}
Which shows that b1.print will call A::print. If you don't include using
A::print, then A::print wil be hidden in B.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32934