#include <iostream>
#include <memory>
class DynamicObject {
private:
int value;
public:
DynamicObject(int v) : value(v) {
std::cout << "Object created with value: " << value << std::endl;
}
~DynamicObject() {
std::cout << "Object destroyed with value: " << value << std::endl;
}
int getValue() const { return value; }
};
int main() {
// Using raw pointer
DynamicObject* rawPtr = new DynamicObject(42);
std::cout << "Raw pointer value: " << rawPtr->getValue() << std::endl;
delete rawPtr;
// Using smart pointer
std::unique_ptr<DynamicObject> smartPtr = std::make_unique<DynamicObject>(100);
std::cout << "Smart pointer value: " << smartPtr->getValue() << std::endl;
return 0;
}