-----Original Message-----
I'm not quite sure what you're trying to do here, but let me see if I
have the basic idea first...
class company
{
public:
char name[20];
...
};
class customer : public company
{
public:
char name[20]; // Overrides company::name
...
void ShowCompanyName( void); // Should display the name from class
company, not customer
};
When you call the ShowCompany function for an object of type company
(or any class that derrives from it), you will by default use the
most-derrived versions of the data members or member functions you
call. You can override this with the scope resolution operator
.
That is what it's for. Consider this:
void company::ShowCompanyName( void)
{
cout << "Customer Name:\t" << customer::name << endl; // Use :: to
override scope, showing the customer information instead.
cout << "Company Name:\t" << name << endl; // By default, we use the
most-derrived version of the member, in this case the company name.
return;
}
If products inherits from company, but you do not define a name member
for the product class, then the above example would still work,
because the name defined for company would still be the most derrived
one in products. If products also has a name member, then you would
simply use the proper class and the scope resolution operator to get
the company and customer names, and then omit it for the product name.
I'm a C++ programmer, and I'm guessing that you're doing something
here with C# and inheritance, but if I'm wrong, please re-post and
I'll see if I can help you out.
Good luck!
JIM
How can access properties of an object lower down in the
hierarchy of my class structure? For example;
Company.Customers(0).Products(0).ShowCompanyName
In the above Show method I want to access the Name
property with the Company class.
Cheers, Robby
.