Re: Variably sized instances of a class




<adebaene@xxxxxxxxxxxxxxxx> wrote:

Most important, it violates the C++ standard, which means
that whatever solution you could devise, it may break on
the next compiler release or service pack, and would most
probalby be not portable.

"not portable" would mean, some of the code might have to
be rewritten for ports. If I wrap the dirty tricks in bag of
templates or whatever, I should be able to minimize the
rewriting to just that.

Can't you fix an upper-bound to the array size [...]

No. Most of them will be small - a few will be huge, and
I want non-virtual (inline) methods to work on both small
and large.

Is it, by any chance, possible to call constructor methods
explicitly on an uninitialized memory block, and will this
initialize the vtable pointer? Or is there a way to explicitly
initialize it?

placement-new.

Thanks - this seems to be what I need.

Now, if I do a naive delete on a *MyClass created this way, am
I right in assuming that this will call the destructor of MyClass,
and after that, deallocate the memory?

If this is the case, things aren't too bad. The destructor will need
to destroy or zero any smart pointers contained in the array, which
shouldn't be too hard.

This will enable me to stick with a relatively standard coding style,
I'll just have to create the objects by means of factory methods
rather than new'ing them.

Regards/Ole Nielsby


.



Relevant Pages

  • Re: Problems with document n1372.pdf
    ... consistant with standard computer science terminology. ... typedef o-type cnd_t; ... I know what a destructor is in C++. ... The xtime_get function sets the xtime object pointed to by xt to hold ...
    (comp.std.c)
  • Re: Problems with document n1372.pdf
    ... consistant with standard computer science terminology. ... The type is an object type o-type that holds an identifier for a condition variable ... I know what a destructor is in C++. ... The xtime_get function sets the xtime object pointed to by xt to hold the current time based on the time base base. ...
    (comp.std.c)
  • Re: Any experience with "The Last One"?
    ... In this International Standard, the examples, the notes, the ... xconstructor ... xdestructor ...
    (comp.lang.c)
  • Re: Any experience with "The Last One"?
    ... In this International Standard, the examples, the notes, the ... xconstructor ... xdestructor ...
    (comp.programming)
  • Re: Numeric Edited and VALUE/MOVE
    ... Initialize Num-Edi to Value ... then all would work "as defined in the Standard". ... MYFLD PIC ZZZ,Z VALUE ALL '9'. ... What happens when you INITIALIZE MYFLD TO VALUE? ...
    (comp.lang.cobol)