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 function from a const virtual function
- From: "CyrusOmega at gmail dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 30 Jul 2007 12:04:59 -0000
- Subject: [Bug c++/32934] No warning when creating a non const derived function from a const virtual function
- References: <bug-32934-14884@http.gcc.gnu.org/bugzilla/>
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
------- 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