why do we put scope resolution operator before iterator whereas we do not use scope resolution operator before scores?
std::vector<double> scores;
std::vector<double>::iterator pv;
why do we put scope resolution operator before iterator whereas we do not use scope resolution operator before scores?
std::vector<double> scores;
std::vector<double>::iterator pv;
std
is a namespace.
std::vector
is a class template in the std
namespace, which makes std::vector<double>
a class.
std::vector<T>::iterator
is a nested type under std::vector<T>
.
If you want to define an object of type std::vector<double>
, you use:
std::vector<double> obj;
If you want to define an object of type std::vector<double>::iterator
, you use:
std::vector<double>::iterator iter;
You're focusing on the wrong part. The first statement defines an object named scores
. The second statement defines an object named pv
. Neither of those names has a ::
in front of it.
vector
is the name of a template defined in the namespace std
, so it is referred to as std::vector
. iterator
is the name of a type that is defined inside std::vector<double>
, so it is referred to as std::vector<double>::iterator
.