Jump to content

Functions and Polymorphism


AggrorJorn
 Share

Recommended Posts

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++.

  • Upvote 1

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

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.

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

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?

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...