Re: Initialize an array of classes?

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



Well, I found a way to get kind of what I'm after. Instead of trying to
have an array of class instances, I can create an array of pointers to class
instances. That way I can use the "new" operator in the body of the
constructor to initialize the array. Of course, this means that I need to
go through my code and change all of the relevant "." operators to "->"
operators, but that's easily enough done in this case.

But I'm still curious as to whether or not it's possible to initialize an
array of classes if the class doesn't have a default constructor.


.



Relevant Pages

  • Re: Function lookup tables?
    ... Ignore any typos the source is good except howto initialize the function ... > I want to initialize the function lookup table array to my member ... > function calls of the class inside of the constructor for the class. ... > What is the correct code to initialize the function pointer array ...
    (comp.lang.cpp)
  • Re: Arrays!
    ... > innitialize a two dimensional array in my constructor of my class. ... you declare and initialize a local variable named ... There is no syntax in C++ to initialize an array that is a member ...
    (microsoft.public.vc.language)
  • Re: cannot have instance field initializers in structs
    ... implement my own default constructor or to manually initialize field ... it would take to allocate my struct. ... if it takes an hour to initialize this ... > array of references and therefore the allocation is always a known thing. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Arrays!
    ... > trying to in the constructor. ... and just have the declaration of the array done ... >> from the array within any accessor function. ... > If you make the array static, initialize it like I did in T3. ...
    (microsoft.public.vc.language)
  • Re: dynamic array
    ... sometimes you need to initialise all elements in an array to 0 ... out any processing based on these elements until you later initialize them. ... constructor for each element is called when the array is created (unlike the ... POD case). ...
    (comp.lang.cpp)