#include <string>
class Person {
public:
Person(std::string name, std::string address);
std::string get_name() const {return _name;}
std::string get_address() const {return _address;}
private:
std::string _name;
std::string _address;
};
Person::Person(std::string name, std::string address)
: _name(name), _address(address)
{
}
#include <iostream>
using namespace std;
int main()
{
Person p("Bob", "New York");
cout << p.get_name() << '\n' << p.get_address() << endl;
return 0;
}
=> add default constructor
#include <string>
class Person {
public:
Person(std::string name, std::string address);
Person() = default;
std::string get_name() const {return _name;}
std::string get_address() const {return _address;}
private:
std::string _name;
std::string _address;
};
Person::Person(std::string name, std::string address)
: _name(name), _address(address)
{
}
#include <iostream>
using namespace std;
int main()
{
Person p;
cout << p.get_name() << '\n' << p.get_address() << endl;
return 0;
}