My Stuff
Username

Password

Articles/Snippets
ASP Classic
C
C#
C++
CSS
HTML
Java
Javascript
MySQL
Perl
PHP
Python
Ruby
Unix/Linux/BSD
VB 6
VB.NET


The Rule Of Three


Your rating: None Average: 5 (1 vote)

Preface

The Rule Of Three is an absolute must to understand for any C++ programmer. It deserves an own chapter, hence the tutorial. It covers the copy constructor, operator=() and the destructor as a combination to fulfill some basic and fundamental requirements when it comes to building a class (or C++ struct) where members allocate memory in a dynamic way. We are going to setup the minimal basics of a String class to work with.

The neat thing about this tutorial is that it covers these three things in detail. Another plus is that this site supports multiple pages and images. So things are nicely grouped an made visible in vivid colors where needed. No chapter in a book in your local store will do that.

There is a little catch.
One needs a very basic understanding of operator overloading: they both need each other to a certain extent. My advice is to learn the very basics of operator overloading first. In this tutorial we are going to overload the assignment operator. Therefore one needs a basic grasp of this technique first. Chapter One of the Operator Overloading tutorial is enough already. So please do read that first before moving on with this. However, if you are familiar with the very basics, then you're set most likely.

In short, these are the (main) prerequisites:

  • Basics of function overloading.
  • Very basics of operator overloading.
  • Basic handling of pointers.
  • Basic handling of references.
  • Basic (but confident) handling of dynamically allocated memory.
  • Understanding the this keyword.
  • Basic handling of functions that return by reference.
  • Basic handling of classes.
  • Confident with constructors.
  • Basic handling of the destructor.

Also, I am available for comments and communication in general on the forums, standard C/C++ section:
http://codenewbie.com/forum/forumdisplay.php?f=16
I really need some feedback otherwise I can't know if this material fulfills the needs of the student.

Good luck!

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • You can use BBCode tags in the text.
  • You can enable syntax highlighting of source code with the following tags: [code], [blockcode], [asp], [awk], [c], [cpp], [csharp], [drupal5], [drupal6], [java], [javascript], [jquery], [mysql], [perl], [perl6], [php], [python], [ruby], [sql], [vb], [vbnet], [xml].
  • Use to create page breaks.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.