C# Inheritance, accessing child members with base functions?

You are hiding myclass1. Mystruct with myclass2. Mystruct They are two completely different objects You can override the object by making it virtual in the base class and override in the subclass, but the object has to keep its type.

You can't change the type of an instance, because that's not type-safe. (FIXME) If you want to change the type of mystruct why? If you just want to access myclass1.

Mystruct from myclass2 you can use base. Mystruct I think.

You are hiding myclass1. Mystruct with myclass2.mystruct. They are two completely different objects.

You can override the object by making it virtual in the base class and override in the subclass, but the object has to keep its type. You can't change the type of an instance, because that's not type-safe. (FIXME) If you want to change the type of mystruct, why?

If you just want to access myclass1. Mystruct from myclass2 you can use base. Mystruct, I think.

Yes strager is right. Instead can you just make it protected in the base class and not declare+initialize a new one, just set it, as if its protected and class2 inherits it, it should have access, I don't think you'll want the internal. – David Aug 29 '09 at 1:48 Thanks guys - unfortunately the type of mystruct needs to be different in both classes.

The overall project is a wrapper around some C++ API's and the API is versioned with two different structs representing the same thing. The XP version of the struct has different contents to the Vista version and my code needs to be agnostic to OS. I've tried to simplify this scenario into the example above.Is there any way to get this working without just copying the getInt() function into myclass2?

(it seems like there is no point to keep inheriting at that stage) – DaveUK Aug 29 '09 at 3:43 @DaveUK, Can you be more specific with your problem? Is each 'myclass' an OS? Wouldn't you have a "base" OS class then several OS-specific subclasses?

– strager Aug 29 '09 at 4:30.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions