In this tutorial we learn how the RVec class can be used to adopt existing memory or allocate some.
class UponCopyPrinter {
public:
UponCopyPrinter() = default;
UponCopyPrinter(UponCopyPrinter &&) = default;
UponCopyPrinter(const UponCopyPrinter &) { std::cout << "Invoking copy c'tor!" << std::endl; }
};
{
RVec<UponCopyPrinter>
v(3);
RVec<UponCopyPrinter> v2(
v.data(),
v.size());
std::cout <<
v.data() <<
" and " << v2.data() << std::endl;
v2.push_back(UponCopyPrinter());
std::cout <<
v.data() <<
" and " << v2.data() << std::endl;
}
0x55e6be5fe6a0 and 0x55e6be5fe6a0
Invoking copy c'tor!
Invoking copy c'tor!
Invoking copy c'tor!
Invoking copy c'tor!
0x55e6be5fe6a0 and 0x55e6be38d0b0
- Date
- May 2018
- Author
- Danilo Piparo
Definition in file vo001_AdoptOrOwnMemory.C.