[C++-sig] Recursion problem while testing inheritance

Stefan Seefeld seefeld at sympatico.ca
Thu Apr 9 16:21:44 CEST 2009


Hi Luciano,

Luciano M. Wolf wrote:
> Hi,
>
> I'm doing some experiments calling methods from parent (or
> grandparent) class. I have a "Base" class defining a "test" virtual
> method. Class "Derived" inherits from "Base" but does not implement
> "test". At Python side (test.py) I redefine test and do a call to
> "Base.test()". The program ends up with a "RuntimeError: maximum
> recursion depth exceeded" error message. Any idea about this? Find
> attached a small example showing how to reproduce this problem.
>   

That's an interesting problem !
I think it is clear what is going on here: when you invoke 'base.test()' 
from python, the interpreter looks up the 'right' method (i.e., picking 
the 'test' attribute from the right base class dictionary. However, the 
way that is implemented means it does its own lookup...including derived 
classes' dictionaries. Thus the circularity that leads to the endless loop.

I'm not sure how to solve this, on a language level. I don't think there 
is a way to convey the fact that the function lookup is (what C++ calls) 
qualified, and thus, that it should be limited to a specific scope (the 
base class).

May be someone else has ideas how to do this ?

Thanks,
       Stefan


-- 

      ...ich hab' noch einen Koffer in Berlin...



More information about the Cplusplus-sig mailing list