When I add
using namespace concurrency;
everything is compiled well but when I add
using namespace concurrency::streams;
then get a lots of compiling error ('ostream':ambiguous symbol) and I understand the reason. The compiler cannot determine which ostream I refer to:
Well, I can always add std directive to all the places that I have ostream, (like below) where the compiler complain:
friend ostream& operator<< (ostream& output, const Node &N);
But there must be another solution to this problem. Could it be so that I should remove any include file that I had before using namespace concurrency::streams?
I have also the following include files in my code:
Aug 26, 2014 at 4:41 PM
I'm not aware of a better solution than not having a 'using namespace std' or 'using namespace concurrency::streams'. Ostream and some others are common names and likely to conflict. You can do using namespace concurrency if you wanted and that will save you
some typing, but in general I don't ever really use using namespace std.
Such ambiguity is exactly the thing namespaces were created to solve, so if you "throw them away" with
statements you've exactly unsolved the problem. As stevetgates' reply suggests, a blanket
using namespace std;
is not a good idea for anything except trivial programs.
If constantly typing
is too much work, consider renaming the namespace, e.g.,
namespace crts = concurrency::streams;
in files where you are using the concurrency::streams members. You can also write
statements in functions, such as
using namespace concurrency::streams; //<- only affects this function