lundi 4 juin 2018

How to initialize array of pointers to classes?

given class (for example in name of X) , I want to allocate array like that:
X** array=new X*[20];

Now some questions about what that I going to get:

  1. How can I do it so that I will get in any cell nullptr in beginning? namely, after the allocation, for any 1<=i<=20 I will get array[i]=nullptr?

  2. Let's look about the following function:

    void Func(){
    X** array=new X*[2];
    X[0]=& X(5); X[1]=& X(3); }

    it's ok to do it like that or that I must to do it with new?

Aucun commentaire:

Enregistrer un commentaire