Click here to Skip to main content
15,887,485 members
Home / Discussions / C#
   

C#

 
GeneralRe: Storing RichText data in Access Database Field Pin
Heath Stewart12-Feb-04 8:36
protectorHeath Stewart12-Feb-04 8:36 
GeneralRe: Storing RichText data in Access Database Field Pin
bjulien12-Feb-04 10:25
bjulien12-Feb-04 10:25 
GeneralExplicit abstract methods. Pin
krisp11-Feb-04 15:29
krisp11-Feb-04 15:29 
GeneralRe: Explicit abstract methods. Pin
Kentamanos11-Feb-04 15:52
Kentamanos11-Feb-04 15:52 
GeneralRe: Explicit abstract methods. Pin
krisp11-Feb-04 16:21
krisp11-Feb-04 16:21 
GeneralRe: Explicit abstract methods. Pin
Kentamanos11-Feb-04 16:45
Kentamanos11-Feb-04 16:45 
GeneralRe: Explicit abstract methods. Pin
krisp11-Feb-04 17:06
krisp11-Feb-04 17:06 
GeneralRe: Explicit abstract methods. Pin
Kentamanos11-Feb-04 17:41
Kentamanos11-Feb-04 17:41 
I only mention multiple inheritance because having syntax to specify exactly whose version of a function you're calling is something that you HAVE to have once your language implements multiple inheritance. There's many an interview question on C++ based upon this type of crap Wink | ;) . If you only have single inheritance, you can call your parent's implementation with a keyword like "base".

One thing to realize is it doesn't matter if the methods return different types at all. Two functions can't have the same name and take the same parameters unless we can use a specific "vtable" to call each one.


That said, think about this:
namespace Test
{

	public interface I
	{
		void MethodA();
	}

	public class C : I
	{
		void Test.I.MethodA()
		{
			// I's version
		}

		public void MethodA()
		{
			// C's version
		}
	}
}


Given this code, instantiate an instance of C and call the I interface version of MethodA without first casting C to an I. AFAIK, it can't be done.

So the mechanism we use to differentiate between which version we're calling is a cast to the specific class. Casting allows us to specify whose "vtable" (a table that points to functions) we want to use.

Now in the case of a derived class, you can't do something like:

DerivedClass d = new DerivedClass();
((DerivedClass)d).MethodA();

because casting something that's already a given class doesn't really do anything.

Casting something to a base class or an interface gives you the "vtable" of that class, which allows us to "specify" a particular method. The problem comes into the fact that the base class's vtable might have a pointer to the derived class in the case the method gets overridden. This is what happens to virtual functions that are redefined with an override. Abstract methods are automatically virtual, they just have no "default" implementation. You are required to supply one in the case of abstract methods.

If we can't use casting to "filter" our vtable and specify which method we're calling, we would need some other method of specifying. C++ ends up using the "::" operator to do this. If you want to call a specific parent class version, you just call it with something like:

ParentClass::MethodA()

It becomes a real mess... Smile | :)

Does any of this help at all? I'm probably not doing this discussion justice. Have you done any C++ in the past?



I, for one, do not think the problem was that the band was down. I think that the problem may have been that there was a Stonehenge monument on the stage that was in danger of being crushed by a dwarf.

-David St. Hubbins
GeneralFile Backup Pin
Demo36011-Feb-04 14:50
Demo36011-Feb-04 14:50 
GeneralRe: File Backup Pin
Heath Stewart12-Feb-04 3:31
protectorHeath Stewart12-Feb-04 3:31 
GeneralRe: File Backup Pin
Anonymous16-Feb-04 5:53
Anonymous16-Feb-04 5:53 
GeneralRe: File Backup Pin
Demo36016-Feb-04 7:33
Demo36016-Feb-04 7:33 
GeneralRe: File Backup Pin
Heath Stewart16-Feb-04 8:50
protectorHeath Stewart16-Feb-04 8:50 
GeneralSurround Sound speaker localization Pin
Matt Frear11-Feb-04 13:00
Matt Frear11-Feb-04 13:00 
GeneralRe: Surround Sound speaker localization Pin
Heath Stewart12-Feb-04 3:28
protectorHeath Stewart12-Feb-04 3:28 
GeneralRe: Surround Sound speaker localization Pin
Matt Frear16-Feb-04 11:11
Matt Frear16-Feb-04 11:11 
Generalclose button on control box of form Pin
visiontec11-Feb-04 11:34
visiontec11-Feb-04 11:34 
GeneralRe: close button on control box of form Pin
Heath Stewart11-Feb-04 12:18
protectorHeath Stewart11-Feb-04 12:18 
GeneralOpinions needed on Win Form Design Pin
MrJJKoolJ11-Feb-04 11:29
MrJJKoolJ11-Feb-04 11:29 
GeneralRe: Opinions needed on Win Form Design Pin
Heath Stewart11-Feb-04 12:15
protectorHeath Stewart11-Feb-04 12:15 
GeneralRe: Opinions needed on Win Form Design Pin
MrJJKoolJ11-Feb-04 14:18
MrJJKoolJ11-Feb-04 14:18 
GeneralRe: Opinions needed on Win Form Design Pin
Heath Stewart12-Feb-04 3:26
protectorHeath Stewart12-Feb-04 3:26 
GeneralSetting Properties through .Net Remoting Pin
Brian Rogan11-Feb-04 11:09
Brian Rogan11-Feb-04 11:09 
Generalproblem with XmlDocument Pin
visiontec11-Feb-04 10:50
visiontec11-Feb-04 10:50 
GeneralRe: problem with XmlDocument Pin
Kentamanos11-Feb-04 11:01
Kentamanos11-Feb-04 11:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.