using Constructors in Classes




This video tutorial explains the constructors in c++.
You are gonna learn what is a constructor, how to define a constructor, how to use constructors in your program, what is the relationship between constructor, class and object in detail with examples.

source code for this tutorial

#include <iostream>
#include <string>

using namespace std;

class Human{
private:
        string name;
        int age;

public:
    Human(){
        name = "nonane";
        age = 0;
        cout << "constructor is called when u create an object of human"<<endl;
    }

    void display(){
    cout <<name<<endl<<age<<endl;
    }

};

int main()
{
    Human anil;
    anil.display();

    return 0;
}