Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Override Keyword in C++ programming
In this tutorial, we will be discussing a program to understand override keyword in C++.
Override keyword is used to override the function in a base class and define a separate function with the same signature in the child class.
Example
#include <iostream>
using namespace std;
class Base {
public:
//function to be override
virtual void func() {
cout << "I am in base" << endl;
}
};
class derived : public Base {
public:
void func(int a) {
cout << "I am in derived class" << endl;
}
};
int main(){
Base b;
derived d;
d.func(6);
return 0;
}
Output
I am in derived class
Advertisements