• 13
• 18
• 19
• 27
• 10

[.net] Inherit problem comes out

This topic is 4375 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

here is code:
public class parentclass
public subclass as new myclass(me)
...
end class

public class anotherparent
public subclass as new inheritclass(me)
...
end class

public class bugclass
public parent as myclass
...
end class

public class myclass
public parent as parentclass
public bugs as arraylist
public sub new(parent as parentclass)
me.parent=parent
end sub
bug.parent=me
end sub
...
end class

public class inheritclass
inherits myclass
public sub new(parent as anotherparent)
me.parent=parent
end sub
...
end class


Problem is: when i make instance of inheritclass inside anotherparent and use add to fill bugs array with bugclass everything work fine but, if i'm trying to access anotherparent.inheritclass.bugs(0).parent i got link with type of inheritclass with parent filled with nothing, i think that comes because in that link parent is reffering to "public parent as parentclass" that is empty but not to "public shadows parent as anotherparent", and here is question: do i need to make also copy of bugclass using inherit with shadowing type of parent in it ? :
public class fixclass
inherits bugclass
...
end class


or there is more simpler way ?

Share on other sites
Sorry, I can't help you, but I was wondering what language this is? (I don't really understand the question since this language is unknown to me - makes my eyes all fuzzy)

Share on other sites
Quote:
 Original post by SOSSorry, I can't help you, but I was wondering what language this is? (I don't really understand the question since this language is unknown to me - makes my eyes all fuzzy)
Looks like VB.

Share on other sites
VB uses the Inherits keyword.
I'd guess at J#?

Share on other sites
I used vbscript tag so it's vb ! And to be exact it's Visual Basic .net and i'm amazed u can't recognize it....

Share on other sites
I guess it does look a tiny bit like VB. Must have been the lack of indentation and capitalization that was throwing me off...

Okey, I read your question 3 times and I don't understand what you're even saying. What is Nothing? What do you mean by the word "link"? That's not a programming term I've ever seen anyone use in this context. Please clarify the question.

Are you saying that when you access bugs(0).parent.parent, it is Nothing? This could be because the "parent" member of inheritclass is not the same as the "parent" member of myclass. They're two different variables. To access the other one, cast bugs(0).parent to inheritclass first. After that, "parent" is the parent of inheritclass.

If you're saying something else, please be more clear.

Share on other sites
You understand question right, i tried to use ctype(anotherparent.inheritclass.bugs(0).parent,inheritclass).parent and it's filled with my value =)) Thx! But it's still mistery to me how i can access shadowed variable if i'm not converting link to proper type....

Share on other sites
Well, you can't. That's what shadowed variables are like. You always need to know the type where the actual shadowed variable is declared. They're two different variables.

You can't change the type of a variable that you got from a parent class, you have to make a new variable. No way around that.

Your best option is to just leave the base class variable abstract enough so that anything you might want to assign to it is accepted (you could just make it of type Object).