home

OOP in CPP

#include<iostream>

using std::string;
using std::cout;
using std::endl;

class Person {
    string d_name;
public:
        void setName(string const name) {
            d_name = name;
        }

        string const &name() const {
            return d_name;
        }
};

int main() {
    auto p = new Person();
    p->setName("test");
    cout << p->name() << endl;
}

Author: Siddhant Kumar