Given that an array name is implicitly converted to a pointer, how do I copy a position of said array into a std::shared_ptr?
#include <iostream>
#include <memory>
int main() {
int arr[3] = {7, 8, 9};
std::cout << arr[0] << std::endl; //-> 7
std::shared_ptr<int> arr_ptr(arr); // Core dumped
std::shared_ptr<int> arr_ptr(&arr[0]); // Core dumped
std::cout << std::endl;
return 0;
}
This confuses me, because there is a legal constructor from a raw pointer in the specification:
template <class U> explicit shared_ptr (U* p);
Why can't I create a shared_ptr to this array position?
Ref: http://www.cplusplus.com/reference/memory/shared_ptr/shared_ptr/
Thx Keith :^)