T O P I C R E V I E W |
Adequat |
Posted - Sep 22 2014 : 08:59:44 AM The "Implement virtual method" inserts, in the declaration, both keywords "virtual" and "override". Is there a way to only use the override keyword?
Because of this new C++ "override" keyword, "virtual" is totally implicit, hence totally useless. If there is no way to achieve that, I would suggest: if the VA option "override keyword for generated C++ method" is activated, then virtual should not be used in the same time. Or at least this should be a global option or a snippet option. |
5 L A T E S T R E P L I E S (Newest First) |
feline |
Posted - Sep 25 2014 : 6:10:06 PM That makes sense, I just wanted to make sure this was not going to break something if implemented. I have put in a feature request for this to see what our developers make of it:
case=85265 |
Adequat |
Posted - Sep 25 2014 : 04:08:25 AM quote: If you are marking your functions as virtual in "baseClass" and then overriding them in both derived classes with only "override" does this work as expected? Does this actually work as if the functions were marked virtual?
Yes for sure! Actually even if you omit both "virtual" and "override" in the derived class, the function are virtual as far as the signature is exactly the same as in the base class. The actual benefit of "override" is to prevent subtle errors caused by a slightly different signature. |
feline |
Posted - Sep 24 2014 : 10:43:01 PM Have you been doing this in your own code? Without writing up some suitable test cases, how does this effect middle classes? So you have:
class baseClass {}; class childClass : public baseClass {}; class grandChildClass : public childClass {};
If you are marking your functions as virtual in "baseClass" and then overriding them in both derived classes with only "override" does this work as expected? Does this actually work as if the functions were marked virtual?
Nothing I have read, or that you are saying, actually implies this. I really like what the override keyword is adding here, I am just weary of breaking something here. |
Adequat |
Posted - Sep 24 2014 : 02:23:40 AM No, "override" does not replace "virtual". But "override" can't be used if the function is not exactly derived from a virtual function. Else that causes a compiler error. Hence "override" implies "virtual", always (but not the other way round).
When the C++ programmer see "override" this automatically means in his mental pattern, "this is also virtual". This means that "virtual" is redundant information in this context. This is more a preference than a problem, but this helps reducing cognitive load (cleaner interface). |
feline |
Posted - Sep 23 2014 : 8:19:12 PM Maybe these are the wrong pages to check, but these MSDN pages are not saying that override replaces virtual:
http://msdn.microsoft.com/en-us/library/41w3sh1c.aspx
http://msdn.microsoft.com/en-us/library/jj678987.aspx
and the examples use both virtual and override.
Is having the virtual keyword as well a problem, or is this just a visual preference? |