I am a complete newbie to smart pointers, and I have never dealt with weak_ptr
in C++.
I have a function in class Y
, that takes in as parameter a weak_ptr
of class X
.
Inside the function in class Y
, I need to access the member functions of class X
through the weak_ptr
.
For reference, here is a rough class definition:
Y.cpp
class Y {
public : Y();
~Y();
int foo(std::weak_ptr<X> x);
};
X.cpp
class X {
public : std::string func1();
int func2();
};
Inside of the foo()
function in class Y
, I need to be able to access the functions func1
and func2
using the weak_ptr x
.
I don't know why I need to use weak_ptr
, but that's what I am supposed to implement.
I am unable to find any beginner-friendly sample code using weak_ptr
.