Category Archives: Library

35. Interface

An interface is a description of what member functions must a class, which inherits this interface, implement. In other words, an interface describes behavior of the class. You can imagine an interface as a list of functions that must be implemented by a class. An interface is created by using __interface keyword: __interface InterfaceName{ //group of functions… Read More »

34. Abstract Class

In C++ class is made abstract by declaring at least one of its functions as <>strong>pure virtual function. A pure virtual function is specified by placing “= 0” in its declaration. Its implementation must be provided by derived classes. Let’s see an example of abstract class in C++ which has one abstract method draw(). Its… Read More »

33. this Pointer

Every object in C++ has access to its own address through an important pointer called this pointer. The this pointer is an implicit parameter to all member functions. Therefore, inside a member function, this may be used to refer to the invoking object. Friend functions do not have a this pointer, because friends are not members of a class. Only member… Read More »

33. Destructors

What is a destructor? Destructor is an instance member function which is invoked automatically whenever an object is going to be destroyed. Meaning, a destructor is the last function that is going to be called before an object is destroyed. The thing is to be noted here, if the object is created by using new or… Read More »

32. Constructor Overloading

As we know function overloading is one of the core features of object-oriented languages. We can use the same name of the functions; whose parameter sets are different. Here we will see how to overload the constructors of C++ classes. The constructor overloading has few important concepts. Overloaded constructors must have the same name and… Read More »

31. Constructor

What is constructor?  A class constructor is a special member function of a class that is executed whenever we create new objects of that class. A constructor will have exact same name as the class and it does not have any return type at all, not even void. Constructors can be very useful for setting initial values… Read More »

30. Protected Access Modifiers

A protected member variable or function is very similar to a private member but it provided one additional benefit that they can be accessed in child classes which are called derived classes. You will learn derived classes and inheritance in next chapter. For now, you can check following example where I have derived one child class SmallBox from a… Read More »

29. Private Access Modifiers

The private Members A private member variable or function cannot be accessed, or even viewed from outside the class. Only the class and friend functions can access private members. By default all the members of a class would be private, for example in the following class width is a private member, which means until you label a member, it… Read More »

28. Public Access Modifiers

The public Members  All the class members declared under the public specifier will be available to everyone. The data members and member functions declared as public can be accessed by other classes and functions too. The public members of a class can be accessed from anywhere in the program using the direct member access operator… Read More »

27. Access Modifiers

Data hiding is one of the important features of Object Oriented Programming which allows preventing the functions of a program to access directly the internal representation of a class type. The access restriction to the class members is specified by the labeled public, private, and protected sections within the class body. The keywords public, private, and protected are called… Read More »