mardi 30 octobre 2018

In a C++ class, do you have to initialize member variables that are arrays?

For example:

class Cls
{
private:
    int x;
    int y;
    int arr[10];

public:
    Cls();
};

Cls::Cls() : x(0), y(0) {}

My understanding is that an uninitialized array will have garbage values. As long as I don't write code that expects the array to have a specific value before filling it, is there any issue with not initializing the array? Or do I need something like this as the constructor:

Cls::Cls() : x(0), y(0), arr() {}

Aucun commentaire:

Enregistrer un commentaire