Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
C++
Please, help me. It's destructor problem
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Salt_Peter, post: 2582279"] #include <iostream> Note how much easier and safe it is to code without pointers. Specially when you use pointers to one character to store an array of characters. Lets face it, does char* name point to a character or an array or characters? Answer: the compiler does not know. Why deal with the amibiguity? pointers == bugs <- remember that Since the code above is using copy construction, you are in need of an appropriate copy constructor. class Person { std::string name; Date birthday; public: Person(std::string s, int d, int m, int y); Person(const Person& r_copy); ~Person(); void print() const; // is not modifying Person, make it const }; Person::Person(std::string s, int d, int m, int y) : name(s), Date(d, m, y) { std::cout << "Person()\n"; } Person::Person(const Person& r_copy) { std::cout << "Person(const Person& copy)\n"; name = r_copy.name; birthday = r_copy.birthday; } Person::~Person() { std::cout << "~Person()\n"; } void Person::print() const { std::cout << "Name : " << name; std::cout << "\nBirthday : "; birthday.print(); std::cout << std::endl; } [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
C++
Please, help me. It's destructor problem
Top