Quote Originally Posted by jpn View Post
And grr, same thing with the declaration story. I some why thought that a private or protected method couldn't be declared as public in a subclass. Neither gcc 4 or msvc 2005 prevents that. Could it be possible that it's prevented in either older version of gcc or msvc?
I think we could have a separate discussion on that, but I also thought that you can't redeclare a private/protected method as public - that you can only reduce the visibility, not increase it. For instance:

Qt Code:
  1. class A {
  2. protected:
  3. virtual int foo(); // virtual so can be overrriden
  4. };
  5.  
  6. class B : public A {
  7. private:
  8. int foo(); // overrides A::foo and changes visibility to private
  9. };
  10.  
  11. class C : public B {
  12. //... doesn't have any redeclaration of foo() so if
  13. // one looks at this class definition one doesn't realise
  14. // there is a foo() method defined
  15. };
  16.  
  17. class D : public C {
  18. public:
  19. int foo(); // ???
  20. };
To copy to clipboard, switch view to plain text mode 

Will D::foo() override B::foo()? I thought you can declare a public method with the same signature as a private method of a superclass, but the two methods won't clash and that this is the whole idea of having private scopes. If one can gain access to a virtual private member by redeclaring it as public, then what sense does it make to have private members at all? Did you check that these will be related to the same virtual method or maybe simply the compiler creates two distinct methods from such a declaration?