std :: unique_ptr char数组

时间:2018-06-05 02:01:28

标签: c++ c++14

我在使用带有数组的std :: unique_ptr时发现了一个奇怪的行为,请参阅:

 {
   auto v = std::make_unique<unsigned char []>(10);
   assert(v);
   std::cout << std::hex << v.get() << std::endl; // does not print anything
 }
 {
   auto v = std::make_unique<char []>(10);
   assert(v);
   std::cout << v.get() << std::endl; // does not print anything
 }
 {
   auto v = std::make_unique<uint8_t []>(10);
   assert(v);
   std::cout << v.get() << std::endl; // does not print anything
 }
 {
   auto v = std::make_unique<std::array<uint8_t, 10>>();
   assert(v);
   std::cout << v.get() << std::endl; // works, prints address
 }
 {
   auto v = std::make_unique<uint16_t []>(10);
   assert(v);
   std::cout << v.get() << std::endl; // works, prints address
 }

它不适用于字节大小数组的原因是什么?我错过了一些微不足道的事情吗?上述行为与C ++ 14 Clang 3.8,gcc 4.9和5.2一致。我阅读了C ++标准,并没有找到相关的东西,有一个解决这个问题的答案会很好。

0 个答案:

没有答案