I have written the following code:
#include <iostream>
#include <memory>
using namespace std;
class Foo
{
int x = 0;
public:
int get() const { return x; }
void set(int x) { this->x = x; }
};
int main(){
auto sp = shared_ptr<Foo>(new Foo());
weak_ptr<Foo> wp;
wp = sp;
return 0;
}
I want to call the method set on the shared pointer sp
and also on wp
, what will be the proper way to call it? I found that sp->set(5);
works for a shared pointer, but the same doesn't work for the weak pointer.