# [.net] Inherit problem comes out

## Recommended Posts

Centurion    100
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
SOS    176
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
mutex    1111
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
DrGUI    402
VB uses the Inherits keyword.
I'd guess at J#?

##### Share on other sites
Centurion    100
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
SOS    176
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
Centurion    100
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
SOS    176
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).

##### Share on other sites
Centurion    100
When i'm trying to convert for example inheritclass to myclass calling:
Ctype(inheritclassinstance,myclass) i got compilation error saying "cannot convert to this type..." but using reference i got link to same object with all parameters stored correctly, with type of inheritclass but with parent variable from myclass... That's sounds for me very veird, and i thinking it's some kind of bug of developing shell... I think i must get error or if no default code must convert it correctly so i don't need extra ctype command for that. I can solve this, not a big problem but looks like it's not how it must work... Anyway thanks for helping