Re: G++ takes code, Comeau barfs with "error: qualified name is not
allowed"
On Jan 28, 1:02 am, Jeff Schwab <j...@schwabcenter.com> wrote:
red floyd wrote:
As far as I can tell, this code should be correct. G++ likes it, but
Comeau online hates it.
std::vector<line_t> v(
std::istream_iterator<line_t>(std::cin),
std::istream_iterator<line_t>());
Comeau is mistaking this statement for a function declaration.
I believe Comeau is at fault, but I would love to be
corrected.
It's an interesting question. It looks like a function
declaration. But as Comeau says, the argument in a function
declaration cannot take a qualified name, so it can't be a
(legal) function declaration. Whether this is enough to
disqualify it as a function declaration or not, however, I don't
know. (If instead of std::cin, he had written just cin, or used
the name of a local variable, there would be no doubt that it
was a function declaration.)
You can
work around this issue with:
std::istream_iterator<line_t> in(std::cin), end;
std::vector<line_t> v(in, end);
The more or less standard solution is to put an extra pair of
parentheses around the arguments, e.g.:
std::vector<line_t> v(
(std::istream_iterator<line_t>(std::cin)),
(std::istream_iterator<line_t>()));
(Putting them around either of the arguments is sufficient, but
there's no harm in being consistent.)
--
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