C++ Tutorials

0

Virtual Base Class in C++

Program 1 // Virtual Class in CPP #include<iostream> using namespace std; class A { public: void display() { cout<<“Hello Display Method”; } }; class B:virtual public A{}; class C:public virtual A{}; class D:public B,public...

0

Virtual Function in C++

Program 1 #include<iostream> using namespace std; class Base // abstract class { public: virtual void display()=0; //pure virtual function }; class Derived1:public Base { public: void display() { cout<<“Display of Derived 1 \n “;...

0

Method Overriding in C++

Program 1 // Inheritance in CPP #include<iostream> using namespace std; class Base { public: Base(int n) { cout<<“Constructor of Base class”; } Base(){} }; class Derived:public Base { public: Derived(){} Derived(int n):Base(n) { cout<<“\nConstructor...

0

Inheritance and Mode of Inheritance in C++

Program 1 // Inheritance in CPP #include<iostream> using namespace std; class Base { private: void a_private() { cout<<“Private method”; } protected: void a_protected() { cout<<“Protected method”; } public: void a_public() { cout<<“Public method”; }...

0

Binary Operator Overloading in C++

Program 1 // Operator overloading #include<iostream> using namespace std; class TestAdd { int n; public: TestAdd(int n) { this->n=n; } TestAdd() { n=0; } void display(); TestAdd operator+(TestAdd K); TestAdd operator-(TestAdd K); }; void...

0

Operator Overloading in C++

Program 1 // Operator overloading #include<iostream> using namespace std; class Test { private: int a,b,c; public: Test(int a,int b,int c) { // cout<<“I am constructor”; this->a=a; this->b=b; this->c=c; } void display() { cout<<a<<” “<<b...

0

Inline Functions in C++

Program 1 #include<iostream> using namespace std; class MyMath { public: int square(int n) //implicit / default inline { return n*n; } }; // inline int MyMath::square(int n) //defination // { // return n*n; //...

0

Static Keyword in C++ Part – 2

Program 1 // Static methods in cpp #include<iostream> using namespace std; class Test { private: int n; // non static static string name; public: Test() { n=500; } static void display(); }; string Test::name=”Vikas”;...

0

Static Keyword in C++ Part – 1

Program 1 // No of Object // static #include<iostream> using namespace std; class Test { public: static int count; Test() { count++; } void display() { cout<<count; } }; int Test::count=0; int main() {...