Path: utzoo!attcan!uunet!mcsun!tuvie!inst182 From: inst182@tuvie (Inst.f.Techn.Informatik) Newsgroups: comp.lang.c++ Subject: calling (con|de)structors explicitly Keywords: c++1.2, constructor Message-ID: <1088@tuvie> Date: 7 Feb 90 16:45:17 GMT Organization: TU Vienna EDP-Center, Vienna, AUSTRIA Lines: 55 I have a problem: I want to dynamically create an array of a class as a member of another class. Now I cannot use the new operator, because the constructors of this class all have at least one argument. Thus, I'd like to allocate the memory with malloc and call the constructor explicitly for each element. Can I do anything to make this legal: class foo { /* something */ public: foo(int); ~foo(); } class bar { /* something else */ public: bar(int,int); ~bar(); } bar::bar(int x, int y){ foo *help, *h2; help = (foo *) malloc (sizeof(foo)*x); for (h2 = help ; h2 < help +x ; h2++){ h2->foo(y); } } One way would be to have a function that really dowes the initialization and call this from the constructor. This function, I could also call from the bar::bar() routine, but if I for example do not have the source of foo, that will not be an alternative. *ANY* hints ? Thanx in advance, mike ____ ____ / / / / / Michael K. Gschwind mike@vlsivie.at / / / / / Institute for VLSI-Design mike@vlsivie.uucp ---/ Technical University, Vienna / ___/