All submissions

Access Object with shared_ptr

#include <iostream>
#include <memory>
using namespace std;

class Logger {
public:
    void log() { cout << "Logging data\n"; }
};

int main() {
    // your code here: declare a shared_ptr<Logger> and another shared_ptr that shares the same object
    // call log() using both shared pointers
    shared_ptr<Logger> p{new Logger};
    shared_ptr<Logger> q{p};
    p->log();
    q->log();
    return 0;
}
Loading...

Input

Expected Output

Logging data Logging data