Get premium membership and access questions with answers, video lessons as well as revision papers.

To illustrate exactly when an object is constructed and destructed when returned from a function, create a C++ class called who. Have who's constructor take...

      

To illustrate exactly when an object is constructed and destructed when returned from a function, create a C++ class called who. Have who's constructor take one character argument that will be used to identify an object.Have the constructor display a message similar to this when constructing an object:
Constructing who #X
where x is the identifying character associated with each object when an object is destroyed, have a message similar to this displayed:
Destroying who #x
where, again, x is the identifying character. Finally, create a function called make_who() that returns a who object. Give each object a unique name.Note the output displayed by the program.

  

Answers


Davis
#include
using namespace std;
class who {
char name;
public:
who(char c) {
nam= c;
cout << "Constructing who #";
cout << name << "\n";
}
~who() { cout << "Destructing who #" << name << "\n";} };
who makewho()
{
wh'B ');
return temp;
}
int main()
{
who ob('A');
makewho();
return o;
}
Githiari answered the question on May 12, 2018 at 17:56


Next: other than the incorrect freeing of dynamically allocated memory, think of a situation in which it would be improper to return an object from a...
Previous: Given this class fragment, class samp { double *p; public: samp (do d) { p = (double *) malloc(sizeof(double)); if (!p) exit (1); //allocation error *p = d; } ~samp() {free(p) ;} //... }; ...

View More Computer Science Questions and Answers | Return to Questions Index


Learn High School English on YouTube

Related Questions