Question: The code is compiling - but my output is incorrect. / / File: main.cpp #include staff.h #include using namespace std; int main ( )
The code is compiling but my output is incorrect.
File: main.cpp
#include "staff.h
#include
using namespace std;
int main
Create an array of StaffMembers
StaffMember staff
StaffMembername
StaffMembername
StaffMembername
;
Use the copy constructor explicitly to instantiate a new instance sm
StaffMember smstaff; Explicitly using copy constructor
Call the displayMember function passing the second element of the staff
displayMemberstaff; Display the second member name
Call the getMember function to have it return the third element of the staff array
sm getMemberstaff; Implicitly uses copy constructor
Assign the first element of the staff array to sm
sm staff; This demonstrates the use of the assignment operator explicitly
Create a pointer to a StaffMember, smp and initialize it with a new instance using "name
StaffMember smp new StaffMembername; Demonstrates the use of the argument constructor
Display the new staff member
displayMembersmp;
Release the instance pointed to by smp
delete smp; Demonstrates the use of the destructor
Print the log of operations
cout StaffMember::oss.str; Display the log of operations
return ;
staffh
#ifndef STAFFH
#define STAFFH
#include
#include
using namespace std;
class StaffMember
public:
string name;
static ostringstream oss; stream used for reporting by all objects
argument constructor
StaffMemberconst string& name : namename
oss "ctor: creating name endl;
copy constructor
StaffMemberconst StaffMember& copy : namecopyname
oss "cctor: copying copy.name endl;
desctructor
~StaffMember
oss "dtor: releasing name endl;
assignment operator
const StaffMember& operator const StaffMember& rhs
name rhsname;
oss ao: assigning rhsname endl;
return this;
;
ostringstream StaffMember::oss;
void displayMemberStaffMember staffMember
staffMember would be displayed here
StaffMember getMemberconst StaffMember staff const int index
return staffindex;
#endif
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
