C++ - Programming Language
This course covers the basics of programming in C++. Work your way through the videos/articles and I'll teach you everything you need to know to start your programming journey!

Constructor Function

Lesson 28
Author : GOUP
Last Updated : September, 2020


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;
}