The following is invalid:
#include <memory>
#include <iostream>
typedef double zip[10];
int main()
{
std::unique_ptr<zip> s = std::make_unique<zip>();
(*s)[0] = 2.0;
std::cout << (*s)[0] << std::endl;
return 0;
}
But the following is perfectly valid:
int main()
{
std::shared_ptr<zip> s = std::make_shared<zip>();
(*s)[0] = 2.0;
std::cout << (*s)[0] << std::endl;
return 0;
}
Why the discrepancy? What am I missing?
Aucun commentaire:
Enregistrer un commentaire