![]() |
Inheritance problem
I have two classes A and B. B inherits A, somthing like this
:
public Class A: Windows.Formwhen i display form B, I get the button from A in addition to both text boxes. My questions is, how do i get B to inherit all of A's NON PRIVATE members only? (I don't want the button to show up in B) Thank you |
This isn't possible in C#. It is in C++, but that's another story.
|
I got a workarround. I created a BaseForm with no buttons and only the things i want common in all my forms. Then each new form inherts the base form.
I'm surprised C# doesn't have that capability, I guess you can't have anything. Thanks for the info |
If the button is private , it means that it's only seen in its class, it will not be accesible in other classes ... So, how the hell did it show you the private button from A ?
Or am I misunderstanding the problem ? If i have this : :
public class AIt sais it can't access i because of its protection level. |
xavier, that's what i thought should happen, but it didn't. I guess it has to do with the nature of the program, being graphic and all. But like i said, i got arround it.
|
A private member is still inherited. It just can't be accessed by subclasses.
:
class PersonA protected member can be accessed by subclasses (and I think nested classes). If age was protected, then both lines in accessTest would be valid. When you inherited your form, notice that in both forms the constructor called InitializeComponent(). InitializeComponent is a private method for both forms. Because it is private, they can both exist without having a name conflict. Note that it is not being overriden. When you create an instance of your inherited form, the base constructor is called, and in turn the original InitializeComponent. This sets up the text box and the button. Then, the subclass constructor calls its InitializeComponent. This sets up the second text box. |
The thing was, that i wrote a similar thingy to what OpenLoop described, but i forgot to initialize the button in the base class, so it didn't apear :o .
Thanks for the explanation Dameon. |
| All times are GMT -5. The time now is 4:14 PM. |
Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC