mardi 24 janvier 2017

unique_ptr and normal pointer doesnt match

int a = 1;

int* w = &a;
std::unique_ptr<int> v(new int(a));

cout << "*w: " << *w << endl;// this works
cout << "*v: " << *v << endl;// this works

cout << "w: " << w << endl; // this works
cout << "v: " << v << endl; // this doesnt work
cout << "v: " << v.get() << endl; // this works

I thought unique pointer constructure is just like a normal one. but when i try getting address of this pointer by raw defined name, it shows error on unique_pointer that "no operator matches this operator". it only works by v.get() method

What am i missing?

Aucun commentaire:

Enregistrer un commentaire