Juergen Vigna <[EMAIL PROTECTED]> writes:

| On 05-May-2000 Lars Gullik Bjønnes wrote:
| > Juergen Vigna <[EMAIL PROTECTED]> writes:
| > 
| >| as I have to allocate the insets in the Init() function (otherwise the
| >| above construction of the cellstruct-vector fails as I have 1 inset for
| >| all table-cells)
| > 
| > Why? Are you storing pointers to insets in the vector(s)?
| > 
| 
| No but the cellstruct does have an entry "TextInset * inset" and I
| need to assign this with "inset = new TextInset(buffer)" so if I do:

Hmm...why?

class Bar {
public:
        Bar() : inset(0) {}
        ~Bar() { delete inset; }
        void InitInset(Buffer * b) {
                inset = new Inset(buffer);
        }
private:
        Inset * inset;
};

vector<Bar> bars(10, Bar());
for (vector<Bar>::iterator it = bars.begin();
        it != bars.end(); ++it) {
        (*it).InitInset(buffer);
}

other option:

class Bar {
public:
        Bar() : inset(0) {}
        Bar(Buffer * b) : inset(new Inset(b)) {}
        Bar(Bar const & b) : inset(new Inset(b.inset)) {}
        ~Bar() { delete inset; }
        Bar & operator=(Bar const & b) {
                delete inset;
                inset = new Inset(b.inset);
        }
private:
        inset;
};

then 

vector<Bar> bars(10, Bar(buffer));

should work.

        Lgb

Reply via email to