lundi 29 juin 2015

How to declare unique_ptr of vector?


I am trying to declare a global vector of MyClass using unique_ptr. My compiler is 4.8.4.

glo.h

extern std::unique_ptr<std::vector<MyClass>> gl_vec;

glo.cpp

std::unique_ptr<std::vector<MyClass>> gl_vec;

And in the file where I initialize and use it for the first time in a different *.cpp file:

#include "glo.h"

// within function 
{
    gl_vec = std::unique_ptr<std::vector<MyClass>> ();

    cout << "gl_vec size = " << (*gl_vec).size() << endl; // crashes here
}

Things keep crashing when I use the pointer. Anyone see what I'm doing wrong?


Aucun commentaire:

Enregistrer un commentaire