Francesco wrote:
On 25 Ago, 11:44, James Kanze <james.ka...@gmail.com> wrote:
[..]
The case I run into the most is when I want to initialize the
array directly, instead of using copy:
^^^^^^^
std::vector< int > my_vector(
std::istream_iterator< int >( std::cin ),
std::istream_iterator< int >() ) ;
Stupid compiler doesn't realize that if I'm naming it
"my_vector", then I don't want a function. (And I use this
idiom a lot, since if I'm not modifying the vector later, it
allows me to declare it const.)
Sorry for replying to a post which wasn't addressed to me, James, but
the code you posted above compiles and runs fine (it creates a vector
instead of declaring a function) - at least on my environment.
What environment is that? And how do you know it creates a vector?
> Is it
really expected to rise the parsing problem?
Parsing problem? In what way? Try compiling this:
#include <vector>
#include <iostream>
#include <iterator>
#include <istream>
int main()
{
std::vector< int > my_vector(
std::istream_iterator< int >( std::cin ),
std::istream_iterator< int >() ) ;
my_vector.size();
}
It's not the declaration of 'my_vector' itself that doesn't compile.
The declaration is not of an object, though. The compiler will choke
when I try using the dot operator to call the 'size' member function of
'std::vector'. And the reason is simple: 'my_vector' is not an object
but a function.
assertions. I believe you didn't test your code, because no compiler
should accept declaring a parameter function called "std::cin". In
vector instantiation. Try that yourself.