开发者

Vector initialized with size, impossible to clear

I have this declaration of a multidimensional vector

std::vector< vector < vector  < ofxImage > > > front_objects;

Then I send it to my class when creating it:

Catalog_object * temp = new Catalog_object(&front_objects, numTag);

And then I perform the following:

Catalog_object::Catalog_object(vector< vector < vector  < ofxImage > > > * _front_objects, int numTag) {
    front_objects=_front_objects;
    if (front_objects->size()<numTag+1) {
        front_objects->resize(numTag+1);
    }
}

What I want to do is to populate the main front_objects with vectors of ofxImages from the Catalog_objects, which might share some vectors of vectors of ofxImages.

The problem is that "sometimes" the vector is initialized with garbage and when trying to clear it with

front_objects[numTag].resize(2);

the program crashes with an EXC_BAD_ACCESS

When resizing it with resize(), shouldnt it be filled with empty vectors?

Thanks

Marc

UPDATE

I tried doing like this but I get "uninitialized reference member 'Catalog_object::front_objects'".

Catalog_obje开发者_JAVA技巧ct::Catalog_object(vector< vector < vector  < ofxImage > > > & _front_objects, int numTag) { // CHANGED * FOR &
    std::vector< vector  < vector < ofxImage > > > & front_objects; // CHANGED * FOR &
    front_objects=_front_objects;
    if (front_objects.size()<numTag+1) {
        front_objects.resize(numTag+1);
    }
    front_objects[numTag].resize(2);
}


std::vector< vector < vector  < ofxImage > > > front_objects;
Catalog_object * temp = new Catalog_object(front_objects, numTag); // REMOVED &


Most likely in

front_objects[numTag].resize(2);

numTag holds an invalid index.

Without the relevant code is difficult to say. Effectively you're saying that every time you walk into your kitchen you hear a strange sound. The picture of the cat that's stuck in between two somethings makes it likely that it's the cat, but could be something else. :-)

Cheers & hth.,

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜