Author |
Topic |
|
Adequat
Tomato Guru
182 Posts |
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. |
|
feline
Whole Tomato Software
United Kingdom
19022 Posts |
|
Adequat
Tomato Guru
182 Posts |
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). |
Edited by - Adequat on Sep 24 2014 02:24:57 AM |
|
|
feline
Whole Tomato Software
United Kingdom
19022 Posts |
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. |
zen is the art of being at one with the two'ness |
|
|
Adequat
Tomato Guru
182 Posts |
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
Whole Tomato Software
United Kingdom
19022 Posts |
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 |
zen is the art of being at one with the two'ness |
|
|
|
Topic |
|