[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Versions trouble



> Ok, I got my compiler up and running and compiling some of my old works in C,
> but now when I use even 'iostream' compiler finds eggog like that:
> 'In file included from /usr/include/g++-v3/backward/stream.h:32,
>  from String.cc:14:
> /usr/include/g++-v3/backward/iostream.h:35: using directive `ostream'
> introduced ambiguous type `ostream''
> I know it's probably due to libraries versions mismatch, but I got libstdc++
> exactly the same version as gcc.

You will need to provide more details. Please run the compilation pass
first with the "-v" option, to find out how the various passes of the
compiler are invoked, then with the "--trace-includes" option, to find
out what files are included in what order.

My suspicion is that you managed to mix header files of different gcc
versions, thus combining a 2.95 ::ostream definition with the 3.0
std::ostream. If you have two ostream classes (one on top-level, one
in std), and you bring the second class on top-level with the using
declaration, you get that error.

That actually suggests a different cause: Compiling

class ostream;
#include <iostream.h>

with gcc 3 will produce this exact error. The error is reported
correctly by GCC: You must not forward-declare ostream. First, it is
not a class (but a typedef for a template instantiation), and then, it
is defined in std::, not in the global namespace. Earlier gcc versions
(incorrectly) accepted that code, since they (incorrectly) defined
ostream to be a global class themselves. Use <iosfwd> if you need
forward declarations of ostream.

In this case, nothing would be wrong with your compiler installation:
the bug is in the source code.

Regards,
Martin



Reply to: