Your task is to implement the Object class. It only needs to have a static membe
ID: 3678906 • Letter: Y
Question
Your task is to implement the Object class. It only needs to have a static member named count, which should be incremented each time a new instance of the class is created. You should also provide the appropriate constructors. Do not worry about destructors for this exercise. Save your class in a file named Object.h
Objects.cpp
int Object::count = 0;
Object f(Object someObject){
return someObject;
}
int main(int argc, const char * argv[])
{
Object myObject;
Object another = f(myObject);
cout << another.count << endl;
return 0;
}
Explanation / Answer
##### Object.h ##########
class Object{
private:
public:
Object();
static int count;
};
######## Object.cpp ##########
#include<iostream>
#include "Object.h"
using namespace std;
int Object::count =0;
Object::Object(){
count++;
}
Object f(Object someObject){
return someObject;
}
int main(){
Object myObject;
Object another = f(myObject);
cout << another.count << endl;
return 0;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.