If I crate an object that is managed by a unique pointer such as:
auto pObjectA = std::make_unique<A>();
But I need this object as a parameter of another object:
auto pObjectB = std::make_unique<B>(*objectA);
If objectA is later moved with std::move, will the reference passed to objectB still be valid?
Edit:
class A
{
//(...)
}
class B
{
public:
B(A& objA): m_rObjectA(objA){}
~B();
void DoSomehting() { /*something that calls a method in A*/ }
private:
A& m_rObjectA;
}
int main()
{
auto pObjectA = std::make_unique<A>();
auto pObjectB = std::make_unique<B>(*pObjectA);
std::unique_ptr<A> pA = std::move(pObjectA);
pObjectB.DoSomething();
}