Chaos Project

General => Electronic and Computer Section => Programming / Scripting / Web => Topic started by: Apidcloud on November 11, 2012, 05:14:05 pm

Title: Virtual and Override differences [C++]
Post by: Apidcloud on November 11, 2012, 05:14:05 pm
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

Title: Re: Virtual and Override differences [C++]
Post by: Blizzard on November 12, 2012, 02:28:33 am
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.
Title: Re: Virtual and Override differences [C++]
Post by: Apidcloud on November 12, 2012, 11:54:19 am
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