J
Jayden Shui
Hi All,
I accidently find that the following code works with Visual C++
compilation
#include <memory>
#include <iostream>
using namespace std;
int main()
{
unique_ptr<int> const p = new int(1);
unique_ptr<int>& q = p; // assign a constant to a non-constant
reference
q.reset(new int(2));
cout << *p; // output 2
return 0;
}
My question is from the 2nd statement of assigning a constant to a non-
constant reference. I think the compiler should report an compilation
error, but it doesn't. Is this a bug of the code of unique_ptr in the
std template library?
Thanks a lot!
Jayden
I accidently find that the following code works with Visual C++
compilation
#include <memory>
#include <iostream>
using namespace std;
int main()
{
unique_ptr<int> const p = new int(1);
unique_ptr<int>& q = p; // assign a constant to a non-constant
reference
q.reset(new int(2));
cout << *p; // output 2
return 0;
}
My question is from the 2nd statement of assigning a constant to a non-
constant reference. I think the compiler should report an compilation
error, but it doesn't. Is this a bug of the code of unique_ptr in the
std template library?
Thanks a lot!
Jayden