[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C++ Blues.



>> Looks like a compiler bug (the 2.7.x series of gcc had many serious  
>> problems with C++). I don't have the C++ specs at hand, but I'm sure that  
>> it's not that stupid ;)
>Looks like it is that stupid.  I've had one mail saying it is in the
>C++ specs, and another saying he can reproduce the problem with
>Borland or Visual C++ under NT.  So its not the G++ people we have to
>shoot.

Hi all...  I've been briefly skimming this thread... and I only spent
a couple of minutes on this (I'm at work...) but, is this what you're
trying to do?

   #include <stdio.h>
   
   class A {
   public:
      print(int a) {
         printf("I am from class A\n");
      }
   };
    
   class B: public A {
   public:
      print(int b) {
      A::print(b);
      }
      print(void) {
         printf("I am from class B\n");
      }
   };
    
    
   main()
   {
      A a;
      B b;
   
      a.print(3);
      b.print(3);
   }
 

I imagine you wanted to do it without the explicit A::print()
reference in the B class.  What I found is that if you don't declare
anything with the name print(...) in the B class, it'll take in the
function from the A class.  However, if you do define it, it needs
An explicit reference.  This seems to be independent of whether the
functions are virtual or not.  This was on gcc 2.7.2.3, btw.

Don't ask me... I thought that's what virtual functions were for...
then again, I don't know C++ that well.

l8r,
Danny