F
fabian.lim
Hi,
I have a question on constant variables. In the following code
snippet, I have a function assign() that takes in an iterator to the
private variable v, the number of stuff to assign (int n), and the
information to assign (a const pointer to a class object
Vector<TYPE>.
According to the arrow below, I put a const keyword in the function.
To my knowledge, this means that all private variables in this object
cannot be changed. however, the iterator to the private variable v is
not constant.
Can somebody explain to me why I still can change stuff in the
private variable v??
Thanks in advance
//********************************************************
// Main Vector Class
template <typename TYPE>
class Vector {
vector<TYPE> v;
public:
//********************************************************
// Constructors and Destructor
Vector() { };
~Vector(){ };
//********************************************************
// vector container functions
void assign(typename vector<TYPE>::iterator itr, const int& n, const
Vector<TYPE>& val) const { <--
for (int k=0; k<n; k++){
*itr = val[k]; itr++;
}
}
};
I have a question on constant variables. In the following code
snippet, I have a function assign() that takes in an iterator to the
private variable v, the number of stuff to assign (int n), and the
information to assign (a const pointer to a class object
Vector<TYPE>.
According to the arrow below, I put a const keyword in the function.
To my knowledge, this means that all private variables in this object
cannot be changed. however, the iterator to the private variable v is
not constant.
Can somebody explain to me why I still can change stuff in the
private variable v??
Thanks in advance
//********************************************************
// Main Vector Class
template <typename TYPE>
class Vector {
vector<TYPE> v;
public:
//********************************************************
// Constructors and Destructor
Vector() { };
~Vector(){ };
//********************************************************
// vector container functions
void assign(typename vector<TYPE>::iterator itr, const int& n, const
Vector<TYPE>& val) const { <--
for (int k=0; k<n; k++){
*itr = val[k]; itr++;
}
}
};