Skip to main content

Posts

Inheritance in c++

Hello friends, in this post today, we learn about Inheritance in c++ concept and types of inheritance in c++ . Which  is very important. so lets start... Inheritance  Inheritance   Class can acquire the properties and methods of another class. Inheritance is the process of deriving a new class from an already existing class. In other words" Inherit all the properties and methods of class into another class, is called Inheritance." Inheritance  provides the idea of reusability i.e., code once written can be used again and again in number  of new classes. The new class is called derived class and old class is called base class. The new class can use all or some of the features of the already existing  class and the programmer can define his own members to the new class. Types of Inheritance In c++, there are 5 types of inheritance. Types of Inheritance Syntax of Inheritance:- class derived_classname : access_spacifier base_classname Where class is keyword used to create a clas
Recent posts

Exception handling in c++

Hello friends, i n this post today, we learn about  What is exception handling  in c++ and  how to handle exception in c++ .  so lets start... Exception handling  Exception handling:- Exception is any abnormal behaviour.  In C++ errors can be  two types. 1. Compile time errors and 2. Run time errors. Compile time errors are syntax errors which occurs during the writing of the program.  Most common examples of compile time errors are missing semicolon, missing comma, missing  double quotes, etc. The syntax error is detected during compilation of program, but the Run time  error will detect during execution of program. So, it is very difficult to handle logical error. C++ provides exception  handling mechanism which can be used to trap this exception and running programs smoothly  after catching the exception. The exception handling provides mechanism to handle logical error during execution of program with appropriate response. Steps to handle Run time error: 1. Find the problem (Hit

Operator overloading in c++.

Hello friends, i n this post today, we learn about w hat is operator overloading  in c++ .   so lets start... Operator overloading  Operator overloading:- Operator overloading is compile time polymorphism. Operator overloading refers to overloading of one operator for many different purpose. It is  one of the powerful and fascinating features of the C++ which give additional meaning to  built-in standard operators like +, -, *, /, >, <, < =, > = etc.  For  example, the binary + can be used to add two integer numbers, two float numbers, two  structures variables, two union variables or two class objects. • The operator overloading provides mechanism to perform operations on user defined data type. • When an operator is overloaded with multiple jobs, it is known as operator overloading. • We can give special meaning to any operators in which program it is implemented. Rules for operator overloading:- 1. Only existing operator can be overloaded. 2.  Any overloaded operator fun

Function with Default arguments in c++

Hello friends, i n this post today, we learn about   Function with Default arguments in c++ .  so lets start... Function with default arguments  Function with default arguments:- In C ++ it is possible for a function not to specify all its arguments. Some of the arguments  may be specified their default values at the time of declaring the function.   Default values are specified when the function is declared. We must add default arguments from right to left. We cannot provide a default value to a particular argument in the middle of an argument list. Default arguments are useful in situations where some arguments always have the same value. For Example, passing marks. In a function with default argument, if one argument is default, all successive arguments  must be default. We cannot provide default values in the middle of the arguments or towards  l eft side. We provide few examples: 1. void fun(int x, int y = 20, int z=35); (valid) 2. void fun(int x, int y = 30, int z); (invalid) 3.

Pure virtual function in c++

Hello friends, i n this post today, we learn about what is pure virtual  function in c++ and how to use pure virtual function  in c++ .  so lets start... Pure virtual function in c++ Pure virtual function:- A pure virtual function is a function which has its body set to 0 i.e., the pure virtual function  does not have any body. A pure virtual function means ‘do nothing’ function. A function declared in a way: Syntax:- virtual void display() = 0;  is known as pure virtual function. Here = 0 does not mean that function show is equal  to 0. It simply means that the virtual function show has no body.  The pure virtual function act  as an interface and any class which inherits the class in which pure virtual function is present,  has to provide the implementation for the function show. We can say empty function. A pure virtual function has no definition relative to the base class. Programmers have to redefine pure virtual function in derived class, because it has no definition in base clas