forked from pezy/CppPrimer
-
Notifications
You must be signed in to change notification settings - Fork 4
/
ex12_16.cpp
30 lines (27 loc) · 871 Bytes
/
ex12_16.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
//
// ex12_15.cpp
// Exercise 12.15
//
// Created by pezy on 12/22/14.
// Copyright (c) 2014 pezy. All rights reserved.
//
// Compilers don’t always give easy-to-understand error messages if we attempt to
// copy or assign a unique_ptr. Write a program that contains these errors to see
// how your compiler diagnoses them.
#include <iostream>
#include <string>
#include <memory>
using std::string; using std::unique_ptr;
int main()
{
unique_ptr<string> p1(new string("pezy"));
// unique_ptr<string> p2(p1); // copy
// ^
// Error: Call to implicitly-deleted copy constructor of 'unique_ptr<string>'
//
// unique_ptr<string> p3 = p1; // assign
// ^
// Error: Call to implicitly-deleted copy constructor of 'unique_ptr<string>'
std::cout << *p1 << std::endl;
p1.reset(nullptr);
}