std 3a 3amake shared 3c 3e

Solutions on MaxInterview for std 3a 3amake shared 3c 3e by the best coders in the world

showing results for - "std 3a 3amake shared 3c 3e"
Mads
01 Mar 2018
1// make_shared example
2#include <iostream>
3#include <memory>
4
5int main () {
6
7  std::shared_ptr<int> foo = std::make_shared<int> (10);
8  // same as:
9  std::shared_ptr<int> foo2 (new int(10));
10
11  auto bar = std::make_shared<int> (20);
12
13  auto baz = std::make_shared<std::pair<int,int>> (30,40);
14
15  std::cout << "*foo: " << *foo << '\n';
16  std::cout << "*bar: " << *bar << '\n';
17  std::cout << "*baz: " << baz->first << ' ' << baz->second << '\n';
18
19  return 0;
20}