What is a function Object native code in C++?

Are you searching for this On GOOGLE What is a function Object native code in C++? then stop your searches because you are in right place. Today I will tell you about What is the function of Object native code in C++?.

What is Constructor in C++ for example?

What is a function Object native code in C++?



In C++, a function Object() { [native code] } is a specific member function with the same name as its class that is used to initialise a variable value to an object's data members. When a class object is created, it is automatically checked.

CONSTRUCTOR TYPES:


There are three sorts of constructors.

1.Constructor by default
2.Constructor with parameters
3.Make a copy of the function Object() { [native code] }.

888888888888888888888888 

SOURCE CODE BELOEW<> 

Default constructor Example:

#include<iostream>
  using namespace std;


  class math// class name
 {
    private:
int a,b,c;

    public:

  void display()
  //function declaration
  

  {

         c=a+b;
cout<<"TOTAL:"<<c;

  }


  math()
 // class name and constructor is same
      {

a=0;//default value
b=0;//default value

      }
  };


  int main()

 {
  math o;//object create for class
  o.display();//function calling
 }

OUTPUT<>

TOTAL=0

Parameterized constructor Example: 

SOURCE CODE BELOEW<>

#include<iostream>

 using namespace std;


 class math// class name

 {

     private:

int a,b,c;

     public:



  void display()

  //function declaration


  {

    c=a+b;

    cout<<"TOTAL:"<<c;

  }


    math(int x,int y)

   {

a=x;//value Assign

b=y;//value Assign

   }

 };

 int main()


 {

    math o(10,20);

    //value given in parameter

    o.display();//function calling

 }

OUTPUT<>

TOTAL=30 Copy constructor  Example:

 SOURCE CODE BELOEW<>

#include<iostream>
  using namespace std;
  class math// class name
 {
     private:
         int a,b,c;

     public:

  void display()//function declaration
  {
     c=a+b;
     cout<<"\n TOTAL:"<<c;
  }

  math(int x,int y)//parameterized
 {
     a=x;//value Assign
     b=y;//value Assign
 }

  math(math &x)//copy constructor
 {
   a=x.a;
   b=x.b;
 }

  };
  int main()
  {
     math o(10,30);
     //parameterized value

     math o1(o);
     //give the copy constructor

     o.display();
     //calling function

     o1.display();
     //copy constuctor object colling
  }

OUTPUT<>

TOTAL=30

TOTAL=30



Post a Comment

0 Comments