Skip to main content

Posts

C++ Namespace

C++ Namespaces Namespaces in C++ are used to organize too many classes so that it can be easy to handle the application. For accessing the class of a namespace, we need to use namespacename::classname. We can use  using  keyword so that we don't have to use complete name all the time. In C++, global namespace is the root namespace. The global::std will always refer to the namespace "std" of C++ Framework. C++ namespace Example Let's see the simple example of namespace which include variable and functions. #include <iostream>    using   namespace  std;   namespace  First {          void  sayHello() {            cout<< "Hello First Namespace" <<endl;               }     }     namespace  Seco...

C++ Function Overriding & Virtual Function

C++ Function Overriding If derived class defines same function as defined in its base class, it is known as function overriding in C++. It is used to achieve runtime polymorphism. It enables you to provide specific implementation of the function which is already provided by its base class. C++ Function Overriding Example Let's see a simple example of Function overriding in C++. In this example, we are overriding the eat() function. #include <iostream>    using   namespace  std;   class  Animal {        public :   void  eat(){     cout<< "Eating..." ;         }       };    class  Dog:  public  Animal     {       public :     void  eat()         {   ...

C++ Overloading (Function and Operator)

C++ Overloading (Function and Operator) If we create two or more members having the same name but different in number or type of parameter, it is known as C++ overloading. In C++, we can overload: methods, constructors, and indexed properties It is because these members have parameters only. Types of overloading in C++ are: Function overloading Operator overloading C++ Function Overloading Function Overloading is defined as the process of having two or more function with the same name, but different in parameters is known as function overloading in C++. In function overloading, the function is redefined by using either different types of arguments or a different number of arguments. It is only through these differences compiler can differentiate between the functions. The  advantage  of Function overloading is that it increases the readability of the program because you don't need to use different names for the same action. C++ Function Overloading Example Let's see the simple...