Posts

Operator Overloading in C++ | Operator Overloading Explained With Real Life Examples

Image
 Operator Overloading in C++ What is operator overloading? Operator overloading means overloading an operator. 😑BRUH... I know you don't understand. Let me put it in a simple manner, suppose if I will say make a faulty calculator where "+"  will do subtraction, "-" will do division, "*" will do addition, "/" will do subtraction. So you will say what are you saying Dhruv.  Hmm, but I am not saying wrong it is possible by operator overloading. Let's understand by your favorite example - YOUR WEDDING EXAMPLE 😍🤣( Now don't start thinking about your bride just understand this concept you boiss) So Suppose when your bride was of 8-10 years then what she says that her father's house is her, her father's car is her car. But when her wedding happed then everything will change like the person is the same but now your bride will say Your car is her car also, your home is her home also. So here the person is the same but ownership is c

Overloading Of Constructor In C++ | Constructor Overloading Explained With Real Life Examples

 Overloading Of Constructor In C++  What is constructor overloading? As you know what is a constructor  and also what is function overloading . So you know constructors are special class methods which is basically a function which runs at the starting of class always. So as you know how to overload a function then the constructor is also a function so you can overload a constructor as same as function overloading. #include   < iostream > using   namespace   std ; class   calculator {      public :      calculator ( int   a ,   int   b )  //constructor with 2 int type parameter      {          cout << " I AM CONSTRUCTOR  " << a + b << endl ;      }      calculator ( int   a ,   int   b ,   int   c )  //constructor with 3 int tpe parameter      {          cout << " I AM A OVERLOADED CONSTRUCTOR  " << a + b + c << endl ;      }      }; int   main () {      calculator   c1 ( 1 , 2 );      calculator   c2 ( 1 , 2 , 4 );      retu

Function Overloading In C++ | Function Overloading Explained With Real Life Examples | Function Overloading In OOPs

Image
 Function Overloading In C++  What is function overloading? Function overloading means creating duplicates of the same function but it will be different from that function. WHAT ??. I know you don't understand. So let me explain this concept by a real-life example. So think about your mother, your mother is a woman but she plays many roles like sometimes she is your mother, sometimes she plays the role of wife, sometimes she plays the role of daughter, etc. So your mom is overloading to the different roles she overloads different roles every time. So same function overloading means to overload properties of different functions. And here is the official definition of function overloading -  Function overloading  is a feature in C++ where two or more  functions  can have the same name but different parameters. When a  function  name is  overloaded  with different jobs it is called  Function Overloading . Here in C++ Function overloading mean you overload some other function with the

Pointers In C++ | Pointer Explained With Real Life Examples | Pointers In OOPs C++

Pointers In C++ What is pointer in c++ ? If you searched about pointers in c++ on google probably you saw that  In C++, a  pointer  refers to a variable that holds the address of another..... BlahBlahBlah..... But you won't able to understand too much about pointers. So don't worry I will explain this concept very easily by a real life example.   So before understanding about pointers first you have to understand why we need pointers? As you know basically when you create variable then it will occupy some space in your pc. And when you create a another variable with same value or modify that variable with some other value then it will occupy more space in the pc. For example -  #include   < iostream > using   namespace   std ; int   main () {      int   var   =   12 ;  //Suppose This will occupy some space which ID is AB12      int   var1   =   12 ;  //Now This will also occupy some space which ID will be BB12 (ALWAYS DIFFERENT)           var   =   45 ; //This will also

Container Class In C++ | Container Class Explained With Real Life Examples

 Container Class In C++ What is a container class? A container class is that class in which you can create an object of any other class and use it like you use it in your main()  function. To understand containers more quickly suppose you have a house and a hotel class. So a house class may have data members like a number of rooms, bedroom_size, bedroom_color. And a hotel class may have the same data member as a house but it may have some more functionality like checkin_time, checkout_time, etc. So in this case you can create a hotel as a class container so you can use house data members inside that also. Here is an example of how you can create a container class in C++ -  #include   < iostream > using   namespace   std ; class   house {      public :      int   no_of_rooms   =   5 ;      int   bedroom_size   =   1200 ; //1200 sq.ft.      char   bedroom_color [ 100 ]   =   " red " ;  //red,green,blue }; class   hotel {      public :     //As i defined object of house cl

Array Of Objects In C++ | Array Of Objects Explained With Real Life Example

 Array Of Objects In C++ What is an array of objects? As you know about the array that it is a set of anything like if there is an array of characters then there will be a set of characters. So the same concepts will be applied to objects - A array of objects will be a set of objects. To understand array of objects more clearly suppose you have a form for a job application and you want to send same job application to 100 people. Then rather then creating 100 job application from scratch you can photocopy the same job application form 100 times.Right? So here how you can create array of object in c++ -  #include   < iostream > using   namespace   std ; class   School {      public :        int   std_id ;      int   std_class ;      float   percentage ;      void   add_details ()      {                   cout << " Enter The Student ID:  " << endl ;          cin >> std_id ;          cout << " Enter The Class Of The Student:  " << end

Destructor In C++ | Destructor Explained With Real Life Examples

 Destructor In C++ What is a Destructor ? As you previously understood about Constructor . You know how constructor works so destructor is opposite of that -  What are opposite in destroctor -  - Destructor call the end of a class always - Destructor takes no argument - Destructor won't return anything - To Modify a constructor you should use ~className Other than that Destructor is same as constructor. #include   < iostream > using   namespace   std ; class   myClass {           public :      ~   myClass ()      {          cout << " I AM A DESRUCTOR " << endl ;      }      void   get ()      {          cout << " I am a simple method " << endl ;      }      }; int   main () {      myClass   m1 ;      m1 . get ();      return   0 ; } Output -  I am a simple method I AM A DESRUCTOR Here you can see we define destructor at starting in class but the destructor executed at last always.

Constructor In C++ | Constructor Explained With Real Life Example

 Constructor In C++  What is a constructor? Constructor sounds like it will construct something, right? So yeah it is somewhat related to construction. So I will ask you a question if you want to stay in your house which is not built till now then what will you do? Maybe you will say what are you asking Dhruv. Well, the answer is very simple you will construct your house first. Am I right?. And you can do any change in your house during the construction right. So as in this example, the house will call class and the process of building your house will call the  constructor.  So when you create a class or call an object of any class then first before going into class first your class is calling constructor which will run by default but if you want to modify that constructor then you can do it. Constructor is like a simple function that will run every time when we go inside a class. Here is the official definition of a constructor -  A  constructor  is a member function of a class that

Friend Class In C++ | Friends Class Explained By Real Life Example

 Friend Class In C++  What is a friend class? A friend class is that class that is a friend of any class. BRUH... I mean that as you have a friend which has access to your every private + protected information like what you like in food, who is your gf 😍😂, what is your weakness but only when you declared it as a friend. So as similar to in real life, you can create friends on programming too.  Okay now here is the official definition of friend class -  A  friend class  is a  class  that can access the private and protected members of a  class  in which it is declared as a  friend . This is needed when we want to allow a particular  class  to access the private and protected members of a  class . So here I explained how a friend class explained by a real-life example -  #include   < iostream > using   namespace   std ; //Here is a class of you where your information is stored class   You {      private :      char   gf_name [ 200 ]   =   " Riya " ;      bool   coward  

Friend Function In C++ | What Is Friend Function | Why We Use Friend Function In C++ ?

 Friend Function In C++ What is the friend function in c++? A friend function is a simple function outside a class but it has access to all private + protected members of a class.  But you might think that we have to tell the class that this function is your friend. You are right you have to define the friend function inside the class by the  friend  keyword. To get a better understanding of the friend function let's see an example. Let suppose a bank in a bank there is a lot of data about user i.e. name, age, address, bank balance, etc. so if RBI should have to investigate that bank then RBI should have to access all of its detail. So here bank is a class and RBI should have a friend function to investigate then without interrupting in the original class. What is the advantage of the friend function in C++? A  friend function  is used to access the non-public members of a  class . It allows generating more efficient code. It provides additional functionality which is not normally