#include <iostream>
class SRO {
private:
int* data;
public:
// Constructor
SRO(int value) {
data = new int(value);
std::cout << "Object created with value: " << *data << std::endl;
}
// Copy Constructor
SRO(const SRO& other) {
data = new int(*(other.data));
std::cout << "Object copied. New object value: " << *data << std::endl;
}
// Destructor
~SRO() {
delete data;
std::cout << "Object destroyed" << std::endl;
}
// Getter function
int getValue() const {
return *data;
}
// Setter function
void setValue(int value) {
*data = value;
std::cout << "Value set to: " << *data << std::endl;
}
};
int main() {
// Creating objects
SRO obj1(42);
SRO obj2 = obj1; // Copy constructor called
// Getting and setting values
std::cout << "Value of obj1: " << obj1.getValue() << std::endl;
std::cout << "Value of obj2: " << obj2.getValue() << std::endl;
obj1.setValue(99);
obj2.setValue(77);
return 0;
}