Created
July 7, 2015 14:56
-
-
Save krysseltillada/48b07ba3a2a262929fb9 to your computer and use it in GitHub Desktop.
class Person with constructor(constructor initializer list)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <iostream> | |
| #include "Person.h" | |
| int main() | |
| { | |
| Person p1; | |
| std::cout << p1.address << std::endl | |
| << p1.name << std::endl; | |
| return 0; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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