Virtual and Override differences [C++]

Started by Apidcloud, November 11, 2012, 05:14:05 pm

Previous topic - Next topic

Apidcloud

November 11, 2012, 05:14:05 pm Last Edit: November 11, 2012, 05:32:28 pm by Apidcloud
Hey there,

I've been wondering the differences between virtual and override keywords in native c++. I know how virtual works, I just don't get override, at least in c++.

Say that a child class inherits a function from its parent class, and that you want to add something specific to it. If parent's class function has virtual before its return type, can we just rewrite the function normally? Without adding override at the end?

The thing is, in C#, I believe it's required to add override at the end of the function(if you want to rewrite it), but in native c++ it doesn't seem that way...even though override keyword exists.

After a little search I found that override keyword was later added, in an update but I don't know its use, since it isn't required when "overriding" a procedure/function


Would someone explain that to me? Thanks

Instead of wanting to be somebody else, rather become somebody else



"I will treasure the knowledge like a squirrel treasures acorns."


Gibbo Glast 2D Engine - The sky is no longer a limit

Blizzard

As far as I remember, native C++ does not have the override keyword and you simply declare the method normally, even if it overrides a virtual one. IDK about managed C++.
In C# it was added so you immediately know that there is a method somewhere in a superclass that is being overriden.
Check out Daygames and our games:

King of Booze 2      King of Booze: Never Ever
Drinking Game for Android      Never have I ever for Android
Drinking Game for iOS      Never have I ever for iOS


Quote from: winkioI do not speak to bricks, either as individuals or in wall form.

Quote from: Barney StinsonWhen I get sad, I stop being sad and be awesome instead. True story.

Apidcloud

I asked my programming teacher, and he also said that he didn't know that override keyword existed in native c++.

The thing is, when I first tried to "override" a method, I used override keyword as I would do in managed C++ and it worked normally. Later on, my teacher said that the only requirement to override a method is the virtual keyword, and then I started wondering the use of override in native c++ and after a little search I found that "override" was introduced in a later update. I would just like to know its use in native c++

Thanks
Instead of wanting to be somebody else, rather become somebody else



"I will treasure the knowledge like a squirrel treasures acorns."


Gibbo Glast 2D Engine - The sky is no longer a limit