Creating Objects from a Class in different ways





This video tutorial explains how to create objects in different ways in c++.
You will learn how to create objects in the stack and how to create objects in the heap dynamically in c++ with an example in detail.

source code for this tutorial

#include <iostream>
#include <string>

using namespace std;
class Human{
public:
    string name;
    void introduce(){
        cout << "hi "<<name<<endl;;
    }
};
int main()
{
    Human anil;

    Human *bunty = new Human();

    anil.name = "anil";
    anil.introduce();

    bunty->name = "bunty";
    bunty->introduce();

    return 0;
}