{"id":28577,"date":"2021-03-25T17:12:06","date_gmt":"2021-03-25T11:42:06","guid":{"rendered":"https:\/\/www.mygreatlearning.com\/blog\/class-in-c\/"},"modified":"2025-08-29T18:25:49","modified_gmt":"2025-08-29T12:55:49","slug":"class-in-c","status":"publish","type":"post","link":"https:\/\/www.mygreatlearning.com\/blog\/class-in-c\/","title":{"rendered":"C++\u00a0Classes and Objects"},"content":{"rendered":"\n<p>This guide shows you how to use C++ classes and objects. You will learn what they are. You will also see how they work with clear examples.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-a-c-class\">What is a C++ Class?<\/h2>\n\n\n\n<p>A C++ class is a user-defined data type that serves as a template for creating objects. It defines the structure and behavior of the objects by specifying the data (variables) and functions (methods) that operate on that data.<\/p>\n\n\n\n<p>You use classes to describe properties and actions. For example, a \"Car\" class might have properties like \"color\" and \"speed.\" It might also have actions like \"start\" and \"stop.\"<\/p>\n\n\n\n<p>Here's why classes matter:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><b>Code Organization:<\/b> Classes group related data and functions together. This makes your code neat.<\/li>\n\n\n\n<li><b>Reusability:<\/b> You write a class once. Then you can use it many times to create different objects.<\/li>\n\n\n\n<li><b>Data Protection:<\/b> Classes help protect your data from unwanted changes.<\/li>\n<\/ul>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"defining-a-class\">Defining a Class<\/h3>\n\n\n\n<p>You define a class using the <code>class<\/code> keyword. You give it a name. Then you put its members inside curly braces <code>{}<\/code>.<\/p>\n\n\n\n<p>Here is a simple example of a <code>Car<\/code> class:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nclass Car {\npublic:\n    \/\/ Properties (data members)\n    std::string color;\n    int speed;\n\n    \/\/ Actions (member functions)\n    void start() {\n        \/\/ Code to start the car\n    }\n\n    void stop() {\n        \/\/ Code to stop the car\n    }\n};\n<\/pre><\/div>\n\n\n<p>In this example, <code>Car<\/code> is the name of the class. <code>color<\/code> and <code>speed<\/code> are data members which store information. <code>start()<\/code> and <code>stop()<\/code> are member functions which perform actions. <code>public:<\/code> means you can access these members from outside the class.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"what-is-a-c-object\">What is a C++ Object?<\/h2>\n\n\n\n<p>A C++ object is a real instance of a class. If a class is a blueprint, an object is the actual house built from that blueprint. You create many objects from one class blueprint. Each object has its own set of data.<\/p>\n\n\n\n<p>For example, from the <code>Car<\/code> blueprint, you can create:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A red car with a speed of 100 km\/h.<\/li>\n\n\n\n<li>A blue car with a speed of 120 km\/h.<\/li>\n<\/ul>\n\n\n\n<p>Each of these is a <code>Car<\/code> object. They both come from the <code>Car<\/code> class.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"creating-an-object\">Creating an Object<\/h3>\n\n\n\n<p>You create an object by declaring a variable of the class type.<\/p>\n\n\n\n<p>Here\u2019s how you create <code>Car<\/code> objects:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#include &amp;lt;iostream&gt; \/\/ Needed for output\n#include &amp;lt;string&gt;   \/\/ Needed for string type\n\nclass Car {\npublic:\n    std::string color;\n    int speed;\n\n    void start() {\n        std::cout &amp;lt;&amp;lt; &quot;The &quot; &amp;lt;&amp;lt; color &amp;lt;&amp;lt; &quot; car is starting.&quot; &amp;lt;&amp;lt; std::endl;\n    }\n\n    void stop() {\n        std::cout &amp;lt;&amp;lt; &quot;The &quot; &amp;lt;&amp;lt; color &amp;lt;&amp;lt; &quot; car is stopping.&quot; &amp;lt;&amp;lt; std::endl;\n    }\n};\n\nint main() {\n    Car car1; \/\/ Create an object named car1\n    Car car2; \/\/ Create another object named car2\n\n    return 0;\n}\n<\/pre><\/div>\n\n\n<p>In <code>main()<\/code>, <code>car1<\/code> and <code>car2<\/code> are objects of the <code>Car<\/code> class. They are separate cars.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"accessing-class-members\">Accessing Class Members<\/h3>\n\n\n\n<p>You access data members and member functions of an object using the dot (<code>.<\/code>) operator.<\/p>\n\n\n\n<p>Here's how you work with <code>car1<\/code> and <code>car2<\/code>:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#include &amp;lt;iostream&gt;\n#include &amp;lt;string&gt;\n\nclass Car {\npublic:\n    std::string color;\n    int speed;\n\n    void start() {\n        std::cout &amp;lt;&amp;lt; &quot;The &quot; &amp;lt;&amp;lt; color &amp;lt;&amp;lt; &quot; car is starting.&quot; &amp;lt;&amp;lt; std::endl;\n    }\n\n    void stop() {\n        std::cout &amp;lt;&amp;lt; &quot;The &quot; &amp;lt;&amp;lt; color &amp;lt;&amp;lt; &quot; car is stopping.&quot; &amp;lt;&amp;lt; std::endl;\n    }\n};\n\nint main() {\n    Car car1; \/\/ Create car1 object\n    car1.color = &quot;Red&quot;; \/\/ Set car1&#039;s color\n    car1.speed = 100;   \/\/ Set car1&#039;s speed\n\n    Car car2; \/\/ Create car2 object\n    car2.color = &quot;Blue&quot;; \/\/ Set car2&#039;s color\n    car2.speed = 120;    \/\/ Set car2&#039;s speed\n\n    std::cout &amp;lt;&amp;lt; &quot;Car 1: Color = &quot; &amp;lt;&amp;lt; car1.color &amp;lt;&amp;lt; &quot;, Speed = &quot; &amp;lt;&amp;lt; car1.speed &amp;lt;&amp;lt; std::endl;\n    car1.start(); \/\/ Call start() function for car1\n\n    std::cout &amp;lt;&amp;lt; &quot;Car 2: Color = &quot; &amp;lt;&amp;lt; car2.color &amp;lt;&amp;lt; &quot;, Speed = &quot; &amp;lt;&amp;lt; car2.speed &amp;lt;&amp;lt; std::endl;\n    car2.stop(); \/\/ Call stop() function for car2\n\n    return 0;\n}\n<\/pre><\/div>\n\n\n<p>When you run this code, you see output that shows each car's details and actions.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nCar 1: Color = Red, Speed = 100\nThe Red car is starting.\nCar 2: Color = Blue, Speed = 120\nThe Blue car is stopping.\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"public-and-private-access-specifiers\">Public and Private Access Specifiers<\/h3>\n\n\n\n<p>Classes use <b>access specifiers<\/b> to control how you access their members.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><b><code>public:<\/code><\/b> You can access public members from anywhere in the program. You saw this in the <code>Car<\/code> class example.<\/li>\n\n\n\n<li><b><code>private:<\/code><\/b> You can only access private members from inside the class itself. You cannot access them directly from outside the class. This protects data.<\/li>\n<\/ul>\n\n\n\n<p>Here's an example with private members:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#include &amp;lt;iostream&gt;\n#include &amp;lt;string&gt;\n\nclass Dog {\nprivate:\n    std::string name; \/\/ Private data member\n    int age;          \/\/ Private data member\n\npublic:\n    \/\/ Public functions to set and get private data\n    void setName(std::string n) {\n        name = n;\n    }\n\n    std::string getName() {\n        return name;\n    }\n\n    void setAge(int a) {\n        if (a &gt; 0) { \/\/ Add a check for valid age\n            age = a;\n        } else {\n            std::cout &amp;lt;&amp;lt; &quot;Age cannot be zero or negative.&quot; &amp;lt;&amp;lt; std::endl;\n        }\n    }\n\n    int getAge() {\n        return age;\n    }\n\n    void bark() {\n        std::cout &amp;lt;&amp;lt; name &amp;lt;&amp;lt; &quot; barks loudly!&quot; &amp;lt;&amp;lt; std::endl;\n    }\n};\n\nint main() {\n    Dog myDog;\n\n    \/\/ myDog.name = &quot;Buddy&quot;; \/\/ This would cause an error! &#039;name&#039; is private.\n\n    myDog.setName(&quot;Buddy&quot;); \/\/ Use public function to set name\n    myDog.setAge(3);        \/\/ Use public function to set age\n\n    std::cout &amp;lt;&amp;lt; &quot;My dog&#039;s name is &quot; &amp;lt;&amp;lt; myDog.getName() &amp;lt;&amp;lt; std::endl;\n    std::cout &amp;lt;&amp;lt; &quot;My dog&#039;s age is &quot; &amp;lt;&amp;lt; myDog.getAge() &amp;lt;&amp;lt; std::endl;\n    myDog.bark();\n\n    myDog.setAge(-1); \/\/ This will show an error message from setAge\n\n    return 0;\n}\n<\/pre><\/div>\n\n\n<p>In the <code>Dog<\/code> class, <code>name<\/code> and <code>age<\/code> are private. You cannot change them directly from <code>main()<\/code>. Functions like <code>setName()<\/code> and <code>setAge()<\/code> are public. They provide a controlled way to access and modify private data. This setup helps keep data safe.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nMy dog&#039;s name is Buddy\nMy dog&#039;s age is 3\nBuddy barks loudly!\nAge cannot be zero or negative.\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"constructors\">Constructors<\/h2>\n\n\n\n<p>A <a href=\"https:\/\/www.mygreatlearning.com\/blog\/constructor-in-cpp\/\">constructor<\/a> is a special member function that is automatically called when an object is created. It is used to initialize the object's properties by setting initial values for its data members.<\/p>\n\n\n\n<p>Constructors have the same name as the class. They do not have a return type, not even <code>void<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"parameterized-constructors\">Parameterized Constructors<\/h3>\n\n\n\n<p>Here's a <code>Rectangle<\/code> class with a constructor that takes parameters:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#include &amp;lt;iostream&gt;\n\nclass Rectangle {\nprivate:\n    double length;\n    double width;\n\npublic:\n    \/\/ Constructor\n    Rectangle(double l, double w) {\n        length = l;\n        width = w;\n        std::cout &amp;lt;&amp;lt; &quot;A rectangle object is created.&quot; &amp;lt;&amp;lt; std::endl;\n    }\n\n    double calculateArea() {\n        return length * width;\n    }\n};\n\nint main() {\n    \/\/ This calls the constructor with 5.0 and 3.0\n    Rectangle rect1(5.0, 3.0);\n    std::cout &amp;lt;&amp;lt; &quot;Area of rect1: &quot; &amp;lt;&amp;lt; rect1.calculateArea() &amp;lt;&amp;lt; std::endl;\n\n    \/\/ This calls the constructor with 7.0 and 4.0\n    Rectangle rect2(7.0, 4.0);\n    std::cout &amp;lt;&amp;lt; &quot;Area of rect2: &quot; &amp;lt;&amp;lt; rect2.calculateArea() &amp;lt;&amp;lt; std::endl;\n\n    return 0;\n}\n<\/pre><\/div>\n\n\n<p>When you create <code>rect1<\/code> and <code>rect2<\/code>, the constructor runs. It sets their length and width.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nA rectangle object is created.\nArea of rect1: 15\nA rectangle object is created.\nArea of rect2: 28\n<\/pre><\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"default-constructors\">Default Constructors<\/h3>\n\n\n\n<p>You can also have a <b>default constructor<\/b>. This constructor takes no arguments.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#include &amp;lt;iostream&gt;\n\nclass Box {\nprivate:\n    double height;\n    double width;\n\npublic:\n    \/\/ Default Constructor\n    Box() {\n        height = 1.0; \/\/ Default height\n        width = 1.0;  \/\/ Default width\n        std::cout &amp;lt;&amp;lt; &quot;Default Box created.&quot; &amp;lt;&amp;lt; std::endl;\n    }\n\n    \/\/ Parameterized Constructor\n    Box(double h, double w) {\n        height = h;\n        width = w;\n        std::cout &amp;lt;&amp;lt; &quot;Box with specific dimensions created.&quot; &amp;lt;&amp;lt; std::endl;\n    }\n\n    double getArea() {\n        return height * width;\n    }\n};\n\nint main() {\n    Box box1; \/\/ Calls the default constructor\n    std::cout &amp;lt;&amp;lt; &quot;Area of box1: &quot; &amp;lt;&amp;lt; box1.getArea() &amp;lt;&amp;lt; std::endl;\n\n    Box box2(5.0, 6.0); \/\/ Calls the parameterized constructor\n    std::cout &amp;lt;&amp;lt; &quot;Area of box2: &quot; &amp;lt;&amp;lt; box2.getArea() &amp;lt;&amp;lt; std::endl;\n\n    return 0;\n}\n<\/pre><\/div>\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nDefault Box created.\nArea of box1: 1\nBox with specific dimensions created.\nArea of box2: 30\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"destructors\">Destructors<\/h2>\n\n\n\n<p>A <b>destructor<\/b> is another special member function. It runs automatically when an object is destroyed. This happens when an object goes out of scope. You use destructors to release resources. For example, you might close files or free up memory.<\/p>\n\n\n\n<p>Destructors have the same name as the class, but with a tilde <code>~<\/code> in front. They do not take any arguments. They also do not have a return type.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#include &amp;lt;iostream&gt;\n#include &amp;lt;string&gt;\n\nclass ResourceHandler {\npublic:\n    std::string resourceName;\n\n    ResourceHandler(std::string name) {\n        resourceName = name;\n        std::cout &amp;lt;&amp;lt; &quot;Resource &quot; &amp;lt;&amp;lt; resourceName &amp;lt;&amp;lt; &quot; is acquired.&quot; &amp;lt;&amp;lt; std::endl;\n    }\n\n    \/\/ Destructor\n    ~ResourceHandler() {\n        std::cout &amp;lt;&amp;lt; &quot;Resource &quot; &amp;lt;&amp;lt; resourceName &amp;lt;&amp;lt; &quot; is released.&quot; &amp;lt;&amp;lt; std::endl;\n    }\n\n    void doWork() {\n        std::cout &amp;lt;&amp;lt; &quot;Working with &quot; &amp;lt;&amp;lt; resourceName &amp;lt;&amp;lt; &quot;.&quot; &amp;lt;&amp;lt; std::endl;\n    }\n};\n\nint main() {\n    { \/\/ Start of a new scope\n        ResourceHandler myFile(&quot;MyImportantFile.txt&quot;);\n        myFile.doWork();\n    } \/\/ myFile object is destroyed here, destructor is called\n\n    std::cout &amp;lt;&amp;lt; &quot;Program continues after resource is released.&quot; &amp;lt;&amp;lt; std::endl;\n\n    return 0;\n}\n<\/pre><\/div>\n\n\n<p>When <code>myFile<\/code> goes out of scope at the end of the block, its destructor <code>~ResourceHandler()<\/code> runs. It prints a message showing the resource is released.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nResource MyImportantFile.txt is acquired.\nWorking with MyImportantFile.txt.\nResource MyImportantFile.txt is released.\nProgram continues after resource is released.\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"member-functions-outside-the-class-definition\">Member Functions Outside the Class Definition<\/h2>\n\n\n\n<p>You can define member functions outside the class definition. You do this using the <b>scope resolution operator (<code>::<\/code>)<\/b>. This helps keep class definitions clean, especially for large functions.<\/p>\n\n\n\n<p>Here's an example:<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#include &amp;lt;iostream&gt;\n#include &amp;lt;string&gt;\n\nclass Student {\npublic:\n    std::string name;\n    int studentId;\n\n    void displayInfo(); \/\/ Declaration of the function\n};\n\n\/\/ Definition of the function outside the class\nvoid Student::displayInfo() {\n    std::cout &amp;lt;&amp;lt; &quot;Student Name: &quot; &amp;lt;&amp;lt; name &amp;lt;&amp;lt; std::endl;\n    std::cout &amp;lt;&amp;lt; &quot;Student ID: &quot; &amp;lt;&amp;lt; studentId &amp;lt;&amp;lt; std::endl;\n}\n\nint main() {\n    Student s1;\n    s1.name = &quot;Alice&quot;;\n    s1.studentId = 101;\n    s1.displayInfo(); \/\/ Call the member function\n\n    Student s2;\n    s2.name = &quot;Bob&quot;;\n    s2.studentId = 102;\n    s2.displayInfo();\n\n    return 0;\n}\n<\/pre><\/div>\n\n\n<p>You use <code>Student::<\/code> to tell the compiler that <code>displayInfo<\/code> is part of the <code>Student<\/code> class.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nStudent Name: Alice\nStudent ID: 101\nStudent Name: Bob\nStudent ID: 102\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"object-oriented-programming-oop-concepts\">Object-Oriented Programming (OOP) Concepts<\/h2>\n\n\n\n<p>Classes and objects are fundamental to <b>Object-Oriented Programming (OOP)<\/b>. OOP is a way to design programs using objects. Besides encapsulation (grouping data and functions) and data hiding (using private), two other core OOP concepts are:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><b>Inheritance:<\/b> This lets a new class (derived class) take on properties and behaviors from an existing class (base class). Think of it like a child inheriting traits from a parent. This promotes code reuse.<\/li>\n\n\n\n<li><b><a href=\"https:\/\/www.mygreatlearning.com\/blog\/polymorphism-in-cpp\/\">Polymorphism<\/a>:<\/b> This means \"many forms.\" It allows you to use one interface to represent different underlying forms. For example, a \"Shape\" class might have a <code>draw()<\/code> method, and different shapes (Circle, Square) would implement <code>draw()<\/code> in their own way.<\/li>\n<\/ul>\n\n\n\n<p>While this guide focuses on the basics, understanding these concepts helps you write more flexible and powerful C++ programs.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"putting-it-all-together\">Putting It All Together<\/h2>\n\n\n\n<p>Let's combine what you learned into a complete program. This program creates a <code>Book<\/code> class. It has properties like title and author. It also has functions to display book details.<\/p>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\n#include &amp;lt;iostream&gt;\n#include &amp;lt;string&gt;\n\nclass Book {\nprivate:\n    std::string title;\n    std::string author;\n    int publicationYear;\n\npublic:\n    \/\/ Constructor to initialize book properties\n    Book(std::string t, std::string a, int year) {\n        title = t;\n        author = a;\n        publicationYear = year;\n        std::cout &amp;lt;&amp;lt; &quot;Book &#039;&quot; &amp;lt;&amp;lt; title &amp;lt;&amp;lt; &quot;&#039; created.&quot; &amp;lt;&amp;lt; std::endl;\n    }\n\n    \/\/ Destructor\n    ~Book() {\n        std::cout &amp;lt;&amp;lt; &quot;Book &#039;&quot; &amp;lt;&amp;lt; title &amp;lt;&amp;lt; &quot;&#039; destroyed.&quot; &amp;lt;&amp;lt; std::endl;\n    }\n\n    \/\/ Public function to display book information\n    void displayBookInfo() {\n        std::cout &amp;lt;&amp;lt; &quot;Title: &quot; &amp;lt;&amp;lt; title &amp;lt;&amp;lt; std::endl;\n        std::cout &amp;lt;&amp;lt; &quot;Author: &quot; &amp;lt;&amp;lt; author &amp;lt;&amp;lt; std::endl;\n        std::cout &amp;lt;&amp;lt; &quot;Publication Year: &quot; &amp;lt;&amp;lt; publicationYear &amp;lt;&amp;lt; std::endl;\n    }\n\n    \/\/ Getter function for title\n    std::string getTitle() {\n        return title;\n    }\n};\n\nint main() {\n    std::cout &amp;lt;&amp;lt; &quot;Creating books...&quot; &amp;lt;&amp;lt; std::endl;\n\n    \/\/ Create the first book object\n    Book book1(&quot;The Hobbit&quot;, &quot;J.R.R. Tolkien&quot;, 1937);\n    book1.displayBookInfo();\n    std::cout &amp;lt;&amp;lt; std::endl;\n\n    \/\/ Create the second book object\n    Book book2(&quot;1984&quot;, &quot;George Orwell&quot;, 1949);\n    book2.displayBookInfo();\n    std::cout &amp;lt;&amp;lt; std::endl;\n\n    \/\/ Access title using getter\n    std::cout &amp;lt;&amp;lt; &quot;The title of book1 is: &quot; &amp;lt;&amp;lt; book1.getTitle() &amp;lt;&amp;lt; std::endl;\n    std::cout &amp;lt;&amp;lt; std::endl;\n\n    std::cout &amp;lt;&amp;lt; &quot;Books created. Program continues.&quot; &amp;lt;&amp;lt; std::endl;\n\n    return 0; \/\/ Objects book1 and book2 are destroyed here\n}\n<\/pre><\/div>\n\n\n<p>This program shows:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A <code>Book<\/code> class with private data members for data protection.<\/li>\n\n\n\n<li>A constructor to set initial values when you create a <code>Book<\/code> object.<\/li>\n\n\n\n<li>A destructor that runs when <code>Book<\/code> objects are destroyed.<\/li>\n\n\n\n<li>Public member functions to interact with the object's data.<\/li>\n<\/ul>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: plain; title: ; notranslate\" title=\"\">\nCreating books...\nBook &#039;The Hobbit&#039; created.\nTitle: The Hobbit\nAuthor: J.R.R. Tolkien\nPublication Year: 1937\n\nBook &#039;1984&#039; created.\nTitle: 1984\nAuthor: George Orwell\nPublication Year: 1949\n\nThe title of book1 is: The Hobbit\n\nBooks created. Program continues.\nBook &#039;1984&#039; destroyed.\nBook &#039;The Hobbit&#039; destroyed.\n<\/pre><\/div>\n\n\n<h2 class=\"wp-block-heading\" id=\"next-steps\">Next Steps<\/h2>\n\n\n\n<p>C++ classes and objects help you write organized and efficient code. A class is a blueprint, and an object is a specific instance. You use access specifiers to control data access. Constructors initialize objects, and destructors clean up resources.<\/p>\n\n\n\n<p>Now that you have a solid foundation, try these challenges:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><b>Modify the <code>Dog<\/code> class:<\/b> Add a new private data member like <code>breed<\/code>. Then create public <code>setBreed()<\/code> and <code>getBreed()<\/code> methods.<\/li>\n\n\n\n<li><b>Create your own class:<\/b> Design a <code>BankAccount<\/code> class with private members for <code>accountNumber<\/code> and <code>balance<\/code>. Add public methods to <code>deposit<\/code> and <code>withdraw<\/code> money.<\/li>\n\n\n\n<li><b>Experiment with constructors:<\/b> Add another constructor to the <code>Book<\/code> class that only takes the title and sets the author to \"Unknown\" and publication year to 0 by default.<\/li>\n<\/ul>\n\n\n\n<p>Experimenting with code is a great way to solidify your understanding. What will you build first?<\/p>\n\n\n\n<p>Take your C++ skills to the next level with hands-on practice and real-world examples. Our Pro C++ Programming for Beginners to Advanced course is perfect for anyone looking to pursue a career in software development, game programming, or system architecture.\"<br><\/p>\n\n\n\n    <div class=\"courses-cta-container\">\n        <div class=\"courses-cta-card\">\n            <div class=\"courses-cta-header\">\n                <div class=\"courses-learn-icon\"><\/div>\n                <span class=\"courses-learn-text\">Academy Pro<\/span>\n            <\/div>\n            <p class=\"courses-cta-title\">\n                <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/learn-c-programming-for-beginners-to-advanced\" class=\"courses-cta-title-link\">C++ Programming Course<\/a>\n            <\/p>\n            <p class=\"courses-cta-description\">Master key C++ programming concepts like variables, functions, OOP, and control structures. Build real-world projects such as a banking system and grade management tool.<\/p>\n            <div class=\"courses-cta-stats\">\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-user-icon\"><\/div>\n                    <span>Beginner to Advanced Level<\/span>\n                <\/div>\n                <div class=\"courses-stat-item\">\n                    <div class=\"courses-stat-icon courses-star-icon\"><\/div>\n                    <span>8.1 hrs<\/span>\n                <\/div>\n            <\/div>\n            <a href=\"https:\/\/www.mygreatlearning.com\/academy\/premium\/learn-c-programming-for-beginners-to-advanced\" class=\"courses-cta-button\">\n                Start Free Trial\n                <div class=\"courses-arrow-icon\"><\/div>\n            <\/a>\n        <\/div>\n    <\/div>\n","protected":false},"excerpt":{"rendered":"<p>If you want to write powerful C++ programs, you can do this by understanding C++ classes and objects. They help you organize your code. They also make your programs easier to manage.<\/p>\n","protected":false},"author":41,"featured_media":108767,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_uag_custom_page_level_css":"","site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"set","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[25860],"tags":[36801],"content_type":[],"class_list":["post-28577","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-software","tag-c-programming"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Master C++ Classes and Objects: A Complete Guide<\/title>\n<meta name=\"description\" content=\"Class is object-oriented programming. and class in C++ is a user-defined data type. This article helps you to know more about Class in C++\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.mygreatlearning.com\/blog\/class-in-c\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"C++\u00a0Classes and Objects\" \/>\n<meta property=\"og:description\" content=\"Class is object-oriented programming. and class in C++ is a user-defined data type. This article helps you to know more about Class in C++\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.mygreatlearning.com\/blog\/class-in-c\/\" \/>\n<meta property=\"og:site_name\" content=\"Great Learning Blog: Free Resources what Matters to shape your Career!\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/GreatLearningOfficial\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-03-25T11:42:06+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-08-29T12:55:49+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/cpp-objects-classes.webp\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"619\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/webp\" \/>\n<meta name=\"author\" content=\"Great Learning Editorial Team\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@https:\/\/twitter.com\/Great_Learning\" \/>\n<meta name=\"twitter:site\" content=\"@Great_Learning\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Great Learning Editorial Team\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"5 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/class-in-c\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/class-in-c\\\/\"},\"author\":{\"name\":\"Great Learning Editorial Team\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\"},\"headline\":\"C++\u00a0Classes and Objects\",\"datePublished\":\"2021-03-25T11:42:06+00:00\",\"dateModified\":\"2025-08-29T12:55:49+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/class-in-c\\\/\"},\"wordCount\":1072,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/class-in-c\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/cpp-objects-classes.webp\",\"keywords\":[\"C++ Programming\"],\"articleSection\":[\"IT\\\/Software Development\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/class-in-c\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/class-in-c\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/class-in-c\\\/\",\"name\":\"Master C++ Classes and Objects: A Complete Guide\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/class-in-c\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/class-in-c\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/cpp-objects-classes.webp\",\"datePublished\":\"2021-03-25T11:42:06+00:00\",\"dateModified\":\"2025-08-29T12:55:49+00:00\",\"description\":\"Class is object-oriented programming. and class in C++ is a user-defined data type. This article helps you to know more about Class in C++\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/class-in-c\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/class-in-c\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/class-in-c\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/cpp-objects-classes.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2021\\\/03\\\/cpp-objects-classes.webp\",\"width\":1200,\"height\":619,\"caption\":\"C++ Classes and Objects\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/class-in-c\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"IT\\\/Software Development\",\"item\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/software\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"C++\u00a0Classes and Objects\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"name\":\"Great Learning Blog\",\"description\":\"Learn, Upskill &amp; Career Development Guide and Resources\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\"},\"alternateName\":\"Great Learning\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#organization\",\"name\":\"Great Learning\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/GL-Logo.jpg\",\"width\":900,\"height\":900,\"caption\":\"Great Learning\"},\"image\":{\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/GreatLearningOfficial\\\/\",\"https:\\\/\\\/x.com\\\/Great_Learning\",\"https:\\\/\\\/www.instagram.com\\\/greatlearningofficial\\\/\",\"https:\\\/\\\/www.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/in.pinterest.com\\\/greatlearning12\\\/\",\"https:\\\/\\\/www.youtube.com\\\/user\\\/beaconelearning\\\/\"],\"description\":\"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.\",\"email\":\"info@mygreatlearning.com\",\"legalName\":\"Great Learning Education Services Pvt. Ltd\",\"foundingDate\":\"2013-11-29\",\"numberOfEmployees\":{\"@type\":\"QuantitativeValue\",\"minValue\":\"1001\",\"maxValue\":\"5000\"}},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/#\\\/schema\\\/person\\\/6f993d1be4c584a335951e836f2656ad\",\"name\":\"Great Learning Editorial Team\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"contentUrl\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/02\\\/unnamed.webp\",\"caption\":\"Great Learning Editorial Team\"},\"description\":\"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.\",\"sameAs\":[\"https:\\\/\\\/www.mygreatlearning.com\\\/\",\"https:\\\/\\\/in.linkedin.com\\\/school\\\/great-learning\\\/\",\"https:\\\/\\\/x.com\\\/https:\\\/\\\/twitter.com\\\/Great_Learning\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCObs0kLIrDjX2LLSybqNaEA\"],\"award\":[\"Best EdTech Company of the Year 2024\",\"Education Economictimes Outstanding Education\\\/Edtech Solution Provider of the Year 2024\",\"Leading E-learning Platform 2024\"],\"url\":\"https:\\\/\\\/www.mygreatlearning.com\\\/blog\\\/author\\\/greatlearning\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Master C++ Classes and Objects: A Complete Guide","description":"Class is object-oriented programming. and class in C++ is a user-defined data type. This article helps you to know more about Class in C++","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.mygreatlearning.com\/blog\/class-in-c\/","og_locale":"en_US","og_type":"article","og_title":"C++\u00a0Classes and Objects","og_description":"Class is object-oriented programming. and class in C++ is a user-defined data type. This article helps you to know more about Class in C++","og_url":"https:\/\/www.mygreatlearning.com\/blog\/class-in-c\/","og_site_name":"Great Learning Blog: Free Resources what Matters to shape your Career!","article_publisher":"https:\/\/www.facebook.com\/GreatLearningOfficial\/","article_published_time":"2021-03-25T11:42:06+00:00","article_modified_time":"2025-08-29T12:55:49+00:00","og_image":[{"width":1200,"height":619,"url":"http:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/cpp-objects-classes.webp","type":"image\/webp"}],"author":"Great Learning Editorial Team","twitter_card":"summary_large_image","twitter_creator":"@https:\/\/twitter.com\/Great_Learning","twitter_site":"@Great_Learning","twitter_misc":{"Written by":"Great Learning Editorial Team","Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.mygreatlearning.com\/blog\/class-in-c\/#article","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/class-in-c\/"},"author":{"name":"Great Learning Editorial Team","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad"},"headline":"C++\u00a0Classes and Objects","datePublished":"2021-03-25T11:42:06+00:00","dateModified":"2025-08-29T12:55:49+00:00","mainEntityOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/class-in-c\/"},"wordCount":1072,"commentCount":0,"publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/class-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/cpp-objects-classes.webp","keywords":["C++ Programming"],"articleSection":["IT\/Software Development"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.mygreatlearning.com\/blog\/class-in-c\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.mygreatlearning.com\/blog\/class-in-c\/","url":"https:\/\/www.mygreatlearning.com\/blog\/class-in-c\/","name":"Master C++ Classes and Objects: A Complete Guide","isPartOf":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/class-in-c\/#primaryimage"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/class-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/cpp-objects-classes.webp","datePublished":"2021-03-25T11:42:06+00:00","dateModified":"2025-08-29T12:55:49+00:00","description":"Class is object-oriented programming. and class in C++ is a user-defined data type. This article helps you to know more about Class in C++","breadcrumb":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/class-in-c\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.mygreatlearning.com\/blog\/class-in-c\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/class-in-c\/#primaryimage","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/cpp-objects-classes.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/cpp-objects-classes.webp","width":1200,"height":619,"caption":"C++ Classes and Objects"},{"@type":"BreadcrumbList","@id":"https:\/\/www.mygreatlearning.com\/blog\/class-in-c\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/www.mygreatlearning.com\/blog\/"},{"@type":"ListItem","position":2,"name":"IT\/Software Development","item":"https:\/\/www.mygreatlearning.com\/blog\/software\/"},{"@type":"ListItem","position":3,"name":"C++\u00a0Classes and Objects"}]},{"@type":"WebSite","@id":"https:\/\/www.mygreatlearning.com\/blog\/#website","url":"https:\/\/www.mygreatlearning.com\/blog\/","name":"Great Learning Blog","description":"Learn, Upskill &amp; Career Development Guide and Resources","publisher":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization"},"alternateName":"Great Learning","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.mygreatlearning.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.mygreatlearning.com\/blog\/#organization","name":"Great Learning","url":"https:\/\/www.mygreatlearning.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/06\/GL-Logo.jpg","width":900,"height":900,"caption":"Great Learning"},"image":{"@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/GreatLearningOfficial\/","https:\/\/x.com\/Great_Learning","https:\/\/www.instagram.com\/greatlearningofficial\/","https:\/\/www.linkedin.com\/school\/great-learning\/","https:\/\/in.pinterest.com\/greatlearning12\/","https:\/\/www.youtube.com\/user\/beaconelearning\/"],"description":"Great Learning is a leading global ed-tech company for professional training and higher education. It offers comprehensive, industry-relevant, hands-on learning programs across various business, technology, and interdisciplinary domains driving the digital economy. These programs are developed and offered in collaboration with the world's foremost academic institutions.","email":"info@mygreatlearning.com","legalName":"Great Learning Education Services Pvt. Ltd","foundingDate":"2013-11-29","numberOfEmployees":{"@type":"QuantitativeValue","minValue":"1001","maxValue":"5000"}},{"@type":"Person","@id":"https:\/\/www.mygreatlearning.com\/blog\/#\/schema\/person\/6f993d1be4c584a335951e836f2656ad","name":"Great Learning Editorial Team","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","url":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","contentUrl":"https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2022\/02\/unnamed.webp","caption":"Great Learning Editorial Team"},"description":"The Great Learning Editorial Staff includes a dynamic team of subject matter experts, instructors, and education professionals who combine their deep industry knowledge with innovative teaching methods. Their mission is to provide learners with the skills and insights needed to excel in their careers, whether through upskilling, reskilling, or transitioning into new fields.","sameAs":["https:\/\/www.mygreatlearning.com\/","https:\/\/in.linkedin.com\/school\/great-learning\/","https:\/\/x.com\/https:\/\/twitter.com\/Great_Learning","https:\/\/www.youtube.com\/channel\/UCObs0kLIrDjX2LLSybqNaEA"],"award":["Best EdTech Company of the Year 2024","Education Economictimes Outstanding Education\/Edtech Solution Provider of the Year 2024","Leading E-learning Platform 2024"],"url":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"}]}},"uagb_featured_image_src":{"full":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/cpp-objects-classes.webp",1200,619,false],"thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/cpp-objects-classes-150x150.webp",150,150,true],"medium":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/cpp-objects-classes-300x155.webp",300,155,true],"medium_large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/cpp-objects-classes-768x396.webp",768,396,true],"large":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/cpp-objects-classes-1024x528.webp",1024,528,true],"1536x1536":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/cpp-objects-classes.webp",1200,619,false],"2048x2048":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/cpp-objects-classes.webp",1200,619,false],"web-stories-poster-portrait":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/cpp-objects-classes-640x619.webp",640,619,true],"web-stories-publisher-logo":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/cpp-objects-classes-96x96.webp",96,96,true],"web-stories-thumbnail":["https:\/\/www.mygreatlearning.com\/blog\/wp-content\/uploads\/2021\/03\/cpp-objects-classes-150x77.webp",150,77,true]},"uagb_author_info":{"display_name":"Great Learning Editorial Team","author_link":"https:\/\/www.mygreatlearning.com\/blog\/author\/greatlearning\/"},"uagb_comment_info":0,"uagb_excerpt":"If you want to write powerful C++ programs, you can do this by understanding C++ classes and objects. They help you organize your code. They also make your programs easier to manage.","_links":{"self":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/28577","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/comments?post=28577"}],"version-history":[{"count":5,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/28577\/revisions"}],"predecessor-version":[{"id":111536,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/posts\/28577\/revisions\/111536"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media\/108767"}],"wp:attachment":[{"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/media?parent=28577"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/categories?post=28577"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/tags?post=28577"},{"taxonomy":"content_type","embeddable":true,"href":"https:\/\/www.mygreatlearning.com\/blog\/wp-json\/wp\/v2\/content_type?post=28577"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}