Just like function templates, we can also make and use class templates in our program. With the help of class templates, a whole class could be made generic. Each function declared within the class is a template function by default. Class templates behave much like the function templates though there is a lot more to be associated and understood with them. Class templates can also be specialized like specializing function templates. For this article, I would explain only how to make a simple class, a template class.
C language provides a very wide resource to interact with numbers and other data types to get our problem solved. During this interaction, one usually tends to run off ground and do silly yet serious mistakes that are most of the times unintentional. The mistakes can range from common declaration errors to some serious programming errors that cannot be recognized at the compile time but send the program crashing at runtime. This post is a series of some programming mistakes that can be identified as simple yet grave.
You may recall i started a series about the basics of object oriented programming in C++. This is the second article of the series. Here, I give you an introduction to classes in C++, explaining about the basic syntax and structure, giving an example to illustrate just how to instantiate and use an object after declaring a class.
Linear search, as described last time is ineffective for method for finding piece of information, the key from a large list. If you have a database of one hundred thousand people living in Los Angeles, you would surely have a headache if you were to look at each and every element of that database to look for your key. In such situations, Binary Search comes into play. Binary search is a very efficient searching algorithm especially for large amount of data. For binary search to perform, data in the list has to be sorted beforehand.