Please Help!! This is an C++ problem. Needs to be done with words and explain wh
ID: 640016 • Letter: P
Question
Please Help!! This is an C++ problem. Needs to be done with words and explain why.
Sally The Programmer is working to improve the Mailbox class we have been working with in this course. She decides to make a parameterless constructor so that driver code can conveniently say:
Mailbox m;
and have everything still compile and work properly. In her implementation of the parameterless constructor, she writes:
Mailbox::Mailbox() {
// empty...
}
What is wrong with her approach and what would you recommend she do to avoid potential problems?
Explanation / Answer
Mailbox::Mailbox() {
my_Address = "";
my_Size = 0;
my_contents = 0;
}
is the correct way to go
since, in your Mailbox class there are three member variables.
Constructors are defined to initialize member variables.
so, It would work well If you initialize member variables. Otherwise your member variables will just hold some garbage values.