Initialize an array of classes?

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



Hi all,

I have a class that contains a member variable that is an array of class
instances:

class MyClass {
private:
SomeClass m_someClass;
SomeClass m_arrayOfClasses[2];
};

Now, the SomeClass class doesn't have a default (paramterless) constructor,
so I need to call its constructor in my initialization list of the MyClass
constructor, kind of like this:

// Constructor
MyClass::MyClass(void) :
// This compiles ok
m_someClass( constructor_arguments ),

// This doesn't compile
m_arrayOfClasses[0]( constructor_arguments ),
m_arrayOfClasses[1]( constructor_arguments )
{}

How do I initialize the array of class instances?

TIA - Bob


.



Relevant Pages

  • Re: Initialize an array of classes?
    ... class MyClass { ... the SomeClass class doesn't have a default ... constructor, so I need to call its constructor in my initialization ... How do I initialize the array of class instances? ...
    (microsoft.public.dotnet.languages.vc)
  • Re: Sorting records using sort()
    ... > We have an array of n*m bytes. ... > proxy objects store a pointer to some master descriptor that stores the ... > need a default constructor, the value type needs to be assignable only ...
    (comp.lang.cpp)
  • Re: Create objects using dynamic class names
    ... classes from a common base class and have an array of class references ... Not necessarily an open array, although that neatly coalesces the steps ... The constructor of the base class can only construct an instance of the ... TPageClass = class of TPage; ...
    (comp.lang.pascal.delphi.misc)
  • Re: creating an array of objects - bug in MATLAB example?
    ... Bill August wrote in message ... build arrays in the constructor is given ... mxSetProperty(plhs, num, FieldName, ... already an array of objects/structures,s). ...
    (comp.soft-sys.matlab)
  • Re: Create objects using dynamic class names
    ... classes from a common base class and have an array of class references ... Not necessarily an open array, although that neatly coalesces the steps ... The constructor of the base class can only construct an instance of the ... TPageClass = class of TPage; ...
    (comp.lang.pascal.delphi.misc)