Chapter 15
1: | |
A1: |
#include <string> using namespace std; class RQ1 { private: string st; // a string object public: RQ1() : st("") {} RQ1(const char * s) : st(s) {} ~RQ1() {}; // more stuff }; The explicit copy constructor, destructor, and assignment operator no longer are needed because the string object provides its own memory management. |
2: | |
A2: | You can assign one string object to another. A string object provides its own memory management so that you normally don't have to worry about a string exceeding the capacity of its holder. |
3: | |
A3: |
#include <string> #include <cctype> using namespace std; void ToUpper(string & str) { for (int i = 0; i < str.size(); i++) str[i] = toupper(str[i]); } |
4: | |
A4: |
auto_ptr<int> pia= new int[20]; // wrong, ... |
Get The Waite Group's C++ Primer Plus, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.