Base class method call ?
-
Hi I have Class A with a protected virtual member Method1() and i have another calss Class B inheriting Class A in which i overrided the base class's method Method1() and i also call the base class's Method1() using the base keyword. Now i have another class Class C which inherits Class B and i am overriding Method1(), the problem is now how do i call Class A's Method1() from this class.
Class A { protected virtual Method1() {} } Class B : Class A { protected override Method1() { //code. base.Method1() } } Class C : Class B { protected override Method1() { **QUESTION: HOW TO CALL CLASS A's METHOD1() HERE. I dont want to call Class B's Method1() but want to call Class A's Method1()** } }
F1! F1! F1!....plzzz:( Regards Chettu. -
Hi I have Class A with a protected virtual member Method1() and i have another calss Class B inheriting Class A in which i overrided the base class's method Method1() and i also call the base class's Method1() using the base keyword. Now i have another class Class C which inherits Class B and i am overriding Method1(), the problem is now how do i call Class A's Method1() from this class.
Class A { protected virtual Method1() {} } Class B : Class A { protected override Method1() { //code. base.Method1() } } Class C : Class B { protected override Method1() { **QUESTION: HOW TO CALL CLASS A's METHOD1() HERE. I dont want to call Class B's Method1() but want to call Class A's Method1()** } }
F1! F1! F1!....plzzz:( Regards Chettu.You can't do it directly in C# because B has already overridden Method1. You need to have a protected "forwarding" method in class B that does what you want to. Something like class B : A { protected void ForwardMethod() { base.Method1(); } } It's possible in C++ though, A::Method1 will do the job. Regards Senthil _____________________________ My Blog | My Articles | WinMacro
-
Hi I have Class A with a protected virtual member Method1() and i have another calss Class B inheriting Class A in which i overrided the base class's method Method1() and i also call the base class's Method1() using the base keyword. Now i have another class Class C which inherits Class B and i am overriding Method1(), the problem is now how do i call Class A's Method1() from this class.
Class A { protected virtual Method1() {} } Class B : Class A { protected override Method1() { //code. base.Method1() } } Class C : Class B { protected override Method1() { **QUESTION: HOW TO CALL CLASS A's METHOD1() HERE. I dont want to call Class B's Method1() but want to call Class A's Method1()** } }
F1! F1! F1!....plzzz:( Regards Chettu.You can't, and it would suck if you could. Looks like C should derive from A. Christian Graus - Microsoft MVP - C++
-
You can't, and it would suck if you could. Looks like C should derive from A. Christian Graus - Microsoft MVP - C++
Why would it suck.. i have a case where Class C should inherit Class B and not A isn't this a possible scenario... i guess so....The possible solution i have done is have a method in class B which will call the base method in A. This scenario will hold in events.. where calling the base class is mandatory....
-
Why would it suck.. i have a case where Class C should inherit Class B and not A isn't this a possible scenario... i guess so....The possible solution i have done is have a method in class B which will call the base method in A. This scenario will hold in events.. where calling the base class is mandatory....
chettu wrote: i have a case where Class C should inherit Class B and not A isn't this a possible scenario No, because if inheritance is optional, how could you count on it in any way ? Christian Graus - Microsoft MVP - C++