2
class A {
   private:
      B* my2DArray[max1][max2];
};

How to initialize my2DArray with NULL here?

2 Answers 2

5

Define your own constructor that value initializes the array, setting all of its elements to null pointers. That's done by providing () initializer for the member, which also works for arrays.

class A
{
public:
  A():my2DArray() { }
private:
  B* my2DArray[max1][max2];
};
Sign up to request clarification or add additional context in comments.

Comments

2

You could use memset:

memset(&my2DArray, 0, max1*max2*sizeof(B*));

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.