This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Problem with virtual const


Hello,

Am I misunderstanding something ? In the following code, I do not understand why there is a compile error on line 22.
I have tried with gcc 3.1, 3.4, 4.0 and 4.1, and the result is the same, so there is little chance that it is a bug...


      1 class A
      2 {
      3   public:
      4     virtual ~A() {}
      5     virtual int f(int x)        const {return x;}
      6     virtual int f(int x, int y) const {return f(x+y);}
      7     virtual int g(int x)        const = 0;
      8     virtual int g(int x, int y) const {return g(x+y);}
      9 };
     10
     11 class B : public A
     12 {
     13   public:
     14     virtual ~B() {}
     15     virtual int g(int x) const {return x;}
     16 };
     17
     18 int main(int, char* [])
     19 {
     20   B b;
     21   b.f(4,5); //ok
     22   b.g(4,5); //error !
     23   static_cast<A*>(&b)->g(4,5); //ok
     24
     25   return 0;
     26 }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]