#include左值、右值using namespace std; void func(int *x) { cout << __PRETTY_FUNCTION__ << endl; cout << x << endl; } void func(int x) { cout << __PRETTY_FUNCTION__ << endl; cout << x << endl; } int main() { //func(NULL); //编译报错,因为NULL即代表0又代表空地址 func(nullptr); //nullptr代表空地址 return 0; }
int main() {
int a = 10;
int &b = a; //左值:有内存、有名字 右值:没名字、没内存
//int &&c = a;//无法将左值绑定到右值引用上
const int &c = 20;
int &&d = 20;//可以把右值绑定到右值引用上
//int &&f = d;//一个右值引用变量,本身是一个左值,无法绑定到右值引用上
int &f = d;
return 0;
}
auto_ptr
auto_ptrptr1(new int); auto_ptr ptr2(ptr1); *ptr2 = 20; cout << *ptr1 << endl;//非法
ptr1拷贝给ptr2时,ptr1不再指向原来的地址
//auto_ptr源码
auto_ptr(_Myt& _Right) _THROW0()
: _Myptr(_Right.release())
{ // construct by assuming pointer from _Right auto_ptr
}
_Ty *release() _THROW0()
{ // return wrapped pointer and give up ownership
_Ty *_Tmp = _Myptr;
_Myptr = 0;
return (_Tmp);
}
scoped_ptr
scoped_ptrunique_ptr&> = delete; scoped_ptr & operator=(const scoped_ptr &) = delete;
unique_ptrp1(new int); unique_ptr p2(std::move(p1));



