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?
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.
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 Im missing something but I dont see how a constructor would ever be called twice unless by an explicit call.
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 Im missing something but I dont 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.
[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.