Vector issue

Hi Rooter,

It might be a very simple problem, but I have been puzzled. I want to put pointer to TCanvas objects in a vector but it crashes. If I use array instead of vector, it works.

vector<TCanvas*> cVect;

char ch[10];
string title;
TCanvas *c[5];
for(int i=0; i<5; i++) {
    sprintf(ch, "%d", i+1);
    title  = "canvas_" + string(c);
    c[i] = new TCanvas(title.c_str(), title.c_str(), 800, 650);
    cVect.push_back(c[i]);
    // or cVect.push_back(new TCanvas(title.c_str(), title.c_str(), 800, 650));
}
for(int i=0; i<5; i++) cout << cVect[i]->GetTitle() << endl;

It works if I use

cVect.push_back(&c[i]);

but it does not look logical (am I missing something?).
I want to use vector because I don’t know the size of the array at the initialization time.
Any suggestion will be appreciated.

Thanks.

Well, it need to be compiled and create an executable.

Hi,

or you create a dictionary for vector<TCanvas*>; if you don’t know how: search the forum for loader.C.

Cheers, Axel.