The point of make_shared is to incorporate the managed object into the control block of the shared pointer,
Since you're dealing with C++11, perhaps using a C++11 array would satisfy your goals?
#include <memory>
#include <array>
int main()
{
auto buffer = std::make_shared<std::array<char, 64>>();
}
Note that you can't use a shared pointer the same way as a pointer you'd get from new[], because std::shared_ptr
(unlike std::unique_ptr
, for example) does not provide operator[]
. You'd have to dereference it: (*buffer)[n] = 'a';
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…