Re: Enum oddity
On 25 Ago, 17:33, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
Francesco wrote:
On 25 Ago, 16:28, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
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 chok=
e
when I try using the dot operator to call the 'size' member function o=
f
'std::vector'. And the reason is simple: 'my_vector' is not an obje=
ct
but a function.
Victor, I'm taking on the habit to test the code before making my
assertions. I believe you didn't test your code, because no compiler
should accept declaring a parameter function called "std::cin". In
fact, it doesn't interpret that as a function declaration but as a
vector instantiation. Try that yourself.
You are correct, of course. My mistake. I did check with Comeau, an=
d
it must have pointed that out, but I just concentrated on the second
error message and not the first.
No problem. Good Lord's Compiler always chocked on "Human::Perfect",
and usually "Faulty.front() == me".
Most likely the code isn't supposed to contain 'std::', and that must
have been the intention when James posted his snippet. Not an excuse
for my missing the first error message, just an observation.
Now that you made me think about it, of course James meant that. It
was easy to guess, after all.
Mistakes. They happen.
Best regards,
Francesco