Whole Tomato Software Forums
Whole Tomato Software Forums
Main Site | Profile | Register | Active Topics | Members | Search | FAQ
User name:
Password:
Save Password
Forgot your password?

 All Forums
 Visual Assist
 Feature Requests
 virtual / override
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Adequat
Tomato Guru

182 Posts

Posted - Sep 22 2014 :  08:59:44 AM  Show Profile  Reply with Quote
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
18753 Posts

Posted - Sep 23 2014 :  8:19:12 PM  Show Profile  Reply with Quote
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?

zen is the art of being at one with the two'ness
Go to Top of Page

Adequat
Tomato Guru

182 Posts

Posted - Sep 24 2014 :  02:23:40 AM  Show Profile  Reply with Quote
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
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18753 Posts

Posted - Sep 24 2014 :  10:43:01 PM  Show Profile  Reply with Quote
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
Go to Top of Page

Adequat
Tomato Guru

182 Posts

Posted - Sep 25 2014 :  04:08:25 AM  Show Profile  Reply with Quote
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.
Go to Top of Page

feline
Whole Tomato Software

United Kingdom
18753 Posts

Posted - Sep 25 2014 :  6:10:06 PM  Show Profile  Reply with Quote
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
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
© 2023 Whole Tomato Software, LLC Go To Top Of Page
Snitz Forums 2000