Skip to content

Instantly share code, notes, and snippets.

@krysseltillada
Created July 7, 2015 14:56
Show Gist options
  • Save krysseltillada/48b07ba3a2a262929fb9 to your computer and use it in GitHub Desktop.
Save krysseltillada/48b07ba3a2a262929fb9 to your computer and use it in GitHub Desktop.
class Person with constructor(constructor initializer list)
#include <iostream>
#include "Person.h"
int main()
{
Person p1;
std::cout << p1.address << std::endl
<< p1.name << std::endl;
return 0;
}
#ifndef PERSON_H
#define PERSON_H
#include <iostream>
#include <string>
struct Person {
/*
Person operator=(const Person &person_p) {
name = person_p.name;
address = person_p.address;
return *this;
}
*/
Person (std::string n = "kryssel", std::string a = "las pinas city") :
name(n), address(a) {
std::cout << "object created using a constructor initializer list "
<< std::endl;
}
Person &store(const Person &person_p) {
name = person_p.name;
address = person_p.address;
return *this;
}
std::string name = "none", address = "none";
};
std::istream &input(std::istream &i, Person &rhs)
{
i >> rhs.name;
i >> rhs.address;
return i;
}
std::ostream &display(std::ostream &d, const Person rhs)
{
d << rhs.name << std::endl
<< rhs.address << std::endl;
return d;
}
#endif // PERSON_H
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment