Question: I have used initialization lists a great deal in my C++ programs but wasn't aware that you could allocate memory within them.

So you can do something (as a contrived example) like this:

```
class Test
{
private:
    int* i;
    int* j;
    int count;
    int* k;

public:
    Test(void) : i(new int), j(new int[10]), count(10), k(new int[count])
    {
    }

    ~Test(void)
    {
        delete i;
        delete [] j;
        delete [] k;
    }
};

```

Are there any issues in doing memory allocation in this way? Regarding the order of initialization here is it safe to have a parameter initialized by one initialized in the same list? i.e. as I allocate `count` before I use it is it safe to use or is there some special initialization order I could fall foul of?

Answer: 
There's no specific issue with calling `new` from the initializer list.

However, if you do it for multiple members, it won't be exception-safe, and you risk leaking memory (what if the first `new` call succeeds, but the second throws an exception? Then the first allocation is leaked).

As for relying on the initialization order, that's perfectly safe. Members are initialized in the order in which they're listed in the class declaration. So you can use the value of members initialized early, to initialize "later" members.

Just keep in mind that it's their declaration order inside the class, and *not* their order in the initialization list that determines their initialization order. :)
Suppose that you have:

```
class Foo
{
public:
    T* p1;
    T* p2;

    Foo()
    : p1(new T),
      p2(new T)
    {
    }
};

```

If initializing `p2` fails (either because `new` throws an out of memory exception or because the `T` constructor fails), then `p1` will be leaked. To combat this, C++ allows using `try`/`catch` in initialization lists, but it's usually pretty gross.