Class Templates

Not only can you use templates for a primitive data type within functions, but also within classes. Consider the following example: The methods are similar to a non-template class, however, each method is a template itself, so you have to adjust a few things. For example, you have to specify template<typename T> before each method….

Copy Constructors

We’ve talked about Constructors in C++ already. One of the special methods, along with Destructors, that C++ offers. There is a third, special method which C++ offers. That is called a Copy Constructor. The Copy Constructor is a special type of constructor, which is intended for use when you duplicate an object. Some people will…

Destructors in C++

We’ve looked at Constructors in C++ to create an object, and building an object with new. However, what happens when we no longer need that object? That’s where a destructor is called. It is built into all objects, and if you don’t define one, a default one will be called for you. The destructor’s job…