c++11make-shared

C++11: 'make_shared' is not a member of 'std'


I'm trying to update some of my code, and tried to include make_shared.

I created a class called Mail to send Emails, now i tried to include it:

    auto m =  std::make_shared<Mail>();

The issue is that I'm using a Makefile:

SHELL = /bin/sh
SYSTEM = $(shell uname)
C++ = g++
CC = gcc
DFLAGS = -DGHOST_MYSQL
OFLAGS = -O3
LFLAGS = -lmysqlclient_r -lboost_date_time -lboost_thread -lboost_system -lboost_filesystem -lgmp
CFLAGS = -std=c++0x

The compile has this flag also included:

g++ -o mail.o -std=c++0x -O3 mail.cpp

But im getting the following error:

error: 'make_shared' is not a member of 'std'
  auto m =  std::make_shared<Mail>();
            ^
error: expected primary-expression before '>' token
  auto m =  std::make_shared<Mail>();
                                 ^
error: expected primary-expression before ')' token
  auto m =  std::make_shared<Mail>();
                                   ^
make: *** [ghost.o] Error 1

What did I wrong here?


Solution

  • make_shared needs you to #include <memory>.

    I have no idea why you're looking at your Makefile for this... ?:-)