Constructor Function

Lesson 28
Author : Afrixi
Last Updated : November, 2017


Table of Content

Code

Copyclass Book{
     public:
          string title;
          string author;

          Book(string title, string author){
               this->title = title;
               this->author = author;
          }
};

int main(){

     Book book1("Harry Potter", "JK Rowling");
     cout << book1.title << endl;

     Book book2("Lord of the Rings", "JRR Tolkien");
     cout << book2.title << endl;

     return 0;
}