std::unique_ptrptr = std::make_unique (42); int* rawPtr = ptr.get(); std::cout << *rawPtr; // Output: 42
std::unique_ptrIn this example, a unique pointer to an array of 3 doubles is defined and initialized. The "get" function is used to extract the raw pointer from the unique pointer. The raw pointer is then used to initialize the elements of the array. Finally, the elements of the array are printed using the raw pointer. The UniquePtr class is part of the C++ Standard Library, specifically theptr = std::make_unique (3); double* rawPtr = ptr.get(); for(int i=0; i<3; i++){ rawPtr[i] = i*1.0; } for(int i=0; i<3; i++){ std::cout << rawPtr[i] << " "; // Output: 0 1 2 }