randomwangran / OOP

3 stars 0 forks source link

Initialization #3

Open randomwangran opened 6 years ago

randomwangran commented 6 years ago

https://github.com/randomwangran/cpp/blob/5991dc7b44bb34ec1dea9f9b30e7cdf32f59a41b/learnCpp/Chapter9/9.x/9.x.3.cpp#L9-L10

You can give a default initialization value directly:

    int m_length = 0;
    int *m_array = nullptr;
randomwangran commented 6 years ago

Those two pieces of code are essentially equal to each other because of what I wrote in my constructor:

IntArray(int size = 0) : m_size(size) 
{
    int *m_array = new int[m_size];
}