Let's assume we have the following code:
struct some_class : parent
{
some_class(::other_class oth) :
parent(some_function(oth.some_property), std::move(oth))
{}
};
Of course construction results in undefinied behaviour (crash in my case), since c++ does not specify execution order. But then, how can I retreive the property before the movement? I cannot change the parent.
Create a helper function to construct the parent where you can add sequencing:
parent make_parent(::other_class &&oth) {
auto sf = some_function(oth.some_property);
return parent(sf, std::move(oth));
}
some_class(::other_class oth) :
parent(make_parent(std::move(oth))
{}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With