Josh Posted May 30, 2012 Share Posted May 30, 2012 Virtual IS needed. IMO, you should always make all your class functions and destructors virtual, all the time. Forgetting to do this when you need to will cause some problems that are very hard to track down. While we're talking about C++ rules, please ALWAYS initialize pointers to NULL, ALL THE TIME. I've wasted more time as a result of uninitialized pointers than anything else in C++. 1 Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Brent Taylor Posted May 30, 2012 Share Posted May 30, 2012 Virtual IS needed. IMO, you should always make all your class functions and destructors virtual, all the time. Forgetting to do this when you need to will cause some problems that are very hard to track down. Specifically in regaurds to making all your class functions virtual: This is a bad idea. Unless you're intending the highest derived implementation of a function to ALWAYS be executed, you don't need to mark it as virtual. Virtual destructors however are a damned good idea. While we're talking about C++ rules, please ALWAYS initialize pointers to NULL, ALL THE TIME. I've wasted more time as a result of uninitialized pointers than anything else in C++. Indeed. In addition, always use initialization lists. Quote There are three types of people in this world. People who make things happen. People who watch things happen. People who ask, "What happened?" Let's make things happen. Link to comment Share on other sites More sharing options...
Rick Posted May 30, 2012 Share Posted May 30, 2012 I almost never use initialization lists. I should get in the habit but I hate their syntax and I find it makes ctors harder to read if your class has a decent amount of variables. We can get into how many variables your class should have but putting that aside for now . Besides constants and references in a class and the fact that C++ will do a default initialization list anyway is there any other reason for doing it? I hate the response of you should do it because C++ will do it anyway. Seems odd C++ will do it by default too, but I'm sure it has it's reasons. So am I a bad person for wanting a better looking ctor (in my eyes anyway) at the price of some speed, which probably is pretty meh anyway? Quote Link to comment Share on other sites More sharing options...
Guest Red Ocktober Posted May 30, 2012 Share Posted May 30, 2012 thx for the perspectives guys... --Mike Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.