P
pauldepstein
I am reading Grimshaw and Ortega's "C++ and Numerical Methods." They
construct a vector class which contains the variable vec, a float*
variable where the length of the array (number of components in the
vector) is given by the variable name veclength.
That is what I _do_ understand. What I don't understand is the
coding for the default constructor which includes vec=0;
What does it mean for a pointer to be equal to 0? Presumably this
means that the address of the pointer is 0? What is the significance
of this?
Here is my wild guess. The choice of 0 for the address is arbitrary
and the purpose is to see when the default constructor is operating.
The destructor contains the code if(vec!=0)delete [] vec;
My guess: the important thing is that the 0 in the default constructor
matches the 0 in the destructor. We don't need for this address to be
0 so long as the default address value matches with the destructor
address value.
I reiterate again that this is a guess (which is why I'm asking for
confirmation).
I'm actually a bit uncomfortable with the whole concept of assigning an
address to zero but perhaps I completely misunderstand what's going on.
Thank you,
Paul Epstein
construct a vector class which contains the variable vec, a float*
variable where the length of the array (number of components in the
vector) is given by the variable name veclength.
That is what I _do_ understand. What I don't understand is the
coding for the default constructor which includes vec=0;
What does it mean for a pointer to be equal to 0? Presumably this
means that the address of the pointer is 0? What is the significance
of this?
Here is my wild guess. The choice of 0 for the address is arbitrary
and the purpose is to see when the default constructor is operating.
The destructor contains the code if(vec!=0)delete [] vec;
My guess: the important thing is that the 0 in the default constructor
matches the 0 in the destructor. We don't need for this address to be
0 so long as the default address value matches with the destructor
address value.
I reiterate again that this is a guess (which is why I'm asking for
confirmation).
I'm actually a bit uncomfortable with the whole concept of assigning an
address to zero but perhaps I completely misunderstand what's going on.
Thank you,
Paul Epstein