I have a 2 classes, class A and class B. Class A contains a pointer to a dynamically allocated array of class B's, created in Class A's constructor. I need to pass arguments to Class Bs' constructors when they are allocated. Is there any way to do this, or will I have to call some kind of Init() function? Hopefully this makes sense to someone.
When you allocate an array of dynamic memory, default constructors will be called. There is no way to make it call any other kind of constructor. I suppose Init would be the best option. Alternatively you could malloc and then placement-new, but that might be a mess.
A useful trick is to write all of B's constructor code in Init() and then make the constructor simply call Init(). That way, should you make a change to the code later on, you only have to do it once.