As seen example below iit
object initialization returns as pointer, can anyone explain how is returns as pointer from constructor?
int main()
{
std::istream_iterator<int> iit (std::cin);
std::cout << *iit;
return 0;
}
As seen example below iit
object initialization returns as pointer, can anyone explain how is returns as pointer from constructor?
int main()
{
std::istream_iterator<int> iit (std::cin);
std::cout << *iit;
return 0;
}
There are no pointers here. Seeing *iit
in the code doesn't mean that iit
is a pointer - C++ allows operator overloading on arbitrary operators.
std::istream_iterator<int>
simply overloads unary operator*
.
iit
is not a pointer, and your *iit
is a reference to a int
. See, this is the declaration of std::istream_iterator::operator*
:
const T& operator*() const;
Template class std::istream_iterator
overloads the unary *
operator, in which it "Returns a [...] reference to the current element".
You can read here about the different kinds of iterators, and get to understand the entire concept of it and fundamental part it has in C++.