I am working on an implementation of a simple Vector
class that forms a container for a constant sized double array (following the example on page 51 of A Tour of C++). My issue is with the method int size() const
. It feels odd to define it this way, instead of const int size()
. Both seem to work. Does anyone know the difference, if there is any?
Below is the class declaration and the definition of Vector::size()
.
class Vector{
public:
Vector(int);
Vector(std::initializer_list<double>);
~Vector(){delete[] elem;}
double& operator[](int);
int size() const;
private:
int sz;
double* elem;
};
int Vector::size() const{
return sz;
}
Note: I found similar posts (1,2), but they do not answer my question.