Re: Enum oddity
On Aug 25, 5:33 pm, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
Francesco wrote:
On 25 Ago, 16:28, Victor Bazarov <v.Abaza...@comAcast.net> wrote:
Francesco wrote:
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.
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, and it must have pointed that out, but I just
concentrated on the second error message and not the first.
Most likely the code isn't supposed to contain 'std::', and
that must have been the intention when James posted his
snippet.
Not quite. The code was extracted from real cases where I've
had the problem, and in real code (as opposed to snippets just
written to test a point here), I never read from std::cin, I
read from an std::istream&. Which may have been initialized
with std::cin, of course, but doesn't have a qualified name
(since 9 times out of ten, it's a function argument). Rather
than post a snippet with extra variables or functions, etc., I
"simplified" it to use std::cin. (And since I never write cin
without the qualifier, I ended up with a qualified name, which
causes the code to work as expected. And introduces perhaps yet
another way to disambiguate---except that most of the time, the
symbol is either a local variable or a parameter, so can't be
qualified.)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34