Topic: Even simplier (Was: even MORE weirder ...)
Author: Valentin Bonnard <Bonnard.V@wanadoo.fr>
Date: 1999/10/27 Raw View
Jeet Sukumaran wrote:
> Now here's something from the twilight zone:
>
> void foo(istream& in) {
>
> std::vector<int> buf(std::istream_iterator<int>(in),
> std::istream_iterator<int>);
std::istream_iterator<int> names a _type_.
std::istream_iterator<int> (int) creates a temporary _object_.
See the difference ? See the problem ?
>
> buf.push_back(3); // for example
> // error: buf not declared in this scope!!!???
>
> }
>
> As you can see, the problem is if buf is declared and defined as above,
> it does not exist in foo's scope!
Because buf declaration syntax is bogus, and the compiler
simply ignores it.
--
Valentin Bonnard
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]