"ostream" is ambiguous

Aug 26, 2014 at 1:02 PM
Hi,

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:
Concurrency::streams::basic_ostream<CharType> Concurrency::streams::ostream'
Or
std::ostream
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:

include <cmath>

include <list>

include <string>

include <vector>

include <iostream>

include <iomanip>

include <fstream>

include <sstream>

include <cstdlib>

include <ctime>

include <map>

include <stdexcept>

include <algorithm>

include <locale>

include <hash_map>

include <tchar.h>

Best regards
RezRaz
Coordinator
Aug 26, 2014 at 4:41 PM
Hi RezRaz,

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.

Steve
Aug 27, 2014 at 2:33 AM
Such ambiguity is exactly the thing namespaces were created to solve, so if you "throw them away" with using 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 concurrency::streams::ostream 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 using statements in functions, such as
void use_members_of_long_namespace()
{
    using namespace concurrency::streams;  //<- only affects this function
    file_stream<uint8_t>::open_ostream(...).then(...);
    ...
}