C++ friend, override nested class's function -


I want to override the virtual function in a nested class from a friend (+ child) class. How is this possible? Here is what I have tried:

  class guardian {children of friendly class; Square nested {public: virtual zero nestedfunc () {std :: cout & lt; & Lt; "One";}   } }; Classroom Children: Parents {Zero Child :: Nested :: NestedFun () {std :: cout & lt; & Lt; "Two";}}  

But I find:

  Error: Member can not define work 'Parents :: Nested: : Nestedfunk 'in' hair ' 

(the same error without "hair ::")

As an override, you will need to expand the class and then override it:

  class guardian {friend class child; Square nested {public: virtual zero nestedfunc () {std :: cout & lt; & Lt; "One";}   } }; Classroom Children: Parents {Class ChildNested: Parent :: Nested {public: virtual void nestedfunc () {std :: cout & lt; & Lt; "Two";}}}  

Inner classes are not that special, they can not break the rules of inheritance or provide any special magic that allows you to override a method Do not give this declaration from the class.


Comments

Popular posts from this blog

java - NullPointerException for a 2d Array -

python - Assemble mpeg file unable to play in mediaplayer -

c# - NameSpace Manager or XsltContent to parse aspx page -