[Bug c++/32934] No warning when creating a non const derived function from a const virtual function
CyrusOmega at gmail dot com
gcc-bugzilla@gcc.gnu.org
Mon Jul 30 12:05:00 GMT 2007
------- Comment #2 from CyrusOmega at gmail dot com 2007-07-30 12:04 -------
(In reply to comment #1)
> 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.
>
The problem I am seeing is that I want to inherit from a virtual const function
but I don't want MY derived function to be const. Just because my parent class
thought the member should be const doesn't mean I agree, or am I simply
restricted?
Thanks, and again I am sorry if this is simply a lack of my understanding of
C++.
Andrew
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32934
More information about the Gcc-bugs
mailing list