These snippets don't do the same thing.
In the first snippet, you're
shadowing the "doThing" function from A in B. Anything calling "doThing" with a pointer of type A will call A's version of doThing, even if the pointer points to an instance of B.
In the second snippet, you're actually overriding A's "doThing" function, and calling doThing with a pointer of type A will call the correct function if overridden.
As an example, try these two snippets:
Code: Select all
class Foo : Actor {
override void PostBeginPlay () {
asd ();
}
void asd () {
Console.Printf ("aaa");
}
}
class Bar : Foo {
void asd () {
Console.Printf ("bbb");
}
}
Code: Select all
class Foo : Actor {
override void PostBeginPlay () {
asd ();
}
virtual void asd () {
Console.Printf ("aaa");
}
}
class Bar : Foo {
override void asd () {
Console.Printf ("bbb");
}
}
Spawn "Foo", then spawn "Bar". With the first snippet, you'll get "aaa" with both, while with the second snippet, you'll get "aaa" when spawning Foo and "bbb" when spawning Bar.