Subclassing a class that calls Super.Constructor

Hey there,

I am having problems with my code because I am subclassing a class that calls Super.Constructor which also calls Super.Constructor. This seems to lead to the constructor at the top the hierarchy of sub/superclasses to be called twice. How is this prevented?

Thanks

Super should just go one level up. The top level should just go once. Have you proven that it is being called twice?

Given the hierarchy

Class1
Class2 (super = Class1)
Class3 (super = Class2)

Class3.Constructor will call Class2.Constructor, which in turn calss Class1.Constructor. Are you seeing something different?

[quote=68629:@Tim Hare]Super should just go one level up. The top level should just go once. Have you proven that it is being called twice?

Given the hierarchy

Class1
Class2 (super = Class1)
Class3 (super = Class2)

Class3.Constructor will call Class2.Constructor, which in turn calss Class1.Constructor. Are you seeing something different?[/quote]
Thanks for clarifying this. Because of what you said, I thought the only way that the Constructor would be called twice is if I instituted it twice when I was a beginner in programming. I wrote something like Dim c as new class1, instead of Dim c as class1.

Thanks a ton

Dim c as class1

declares a variable c and initialises it with nil; no object is created and thus no constructor called. Whereas

Dim c as new class1

initialises c with a new instance of class1, so its constructor is called once. Maybe I’m missing something but I don’t see how a constructor would ever be called twice unless by an explicit call.

[quote=68712:@Michael Hußmann]Dim c as class1

declares a variable c and initialises it with nil; no object is created and thus no constructor called. Whereas

Dim c as new class1

initialises c with a new instance of class1, so its constructor is called once. Maybe I’m missing something but I don’t see how a constructor would ever be called twice unless by an explicit call.[/quote]
My code was like this:

dim c as new class1

select case someInteger
case 0
c = new class1subclass
case 1
c = new otherClass1subclass
end select

So I called the constructor for an object with a waist of institution.

Thanks for your input

Answered my own question. But Tim helped lots. Thanks Tim.

[quote=68756:@Oliver Scott-Brown]My code was like this:

[code]
dim c as new class1

select case someInteger
case 0
c = new class1subclass
case 1
c = new otherClass1subclass
end select
[/code][/quote]

In this case the originally created object is subsequently thrown away and replaced by a different object which is wasteful indeed. The constructor would be called twice, but not for the same object. For each instance there would still be only one call.