2

My project uses a third party modules where one of the header file has defined 'errc'

typedef int             errc;

I want to use STL in project but when I add stl header file I get name conflict for errc since its class name in the standard library.

error C2872: 'errc' : ambiguous symbol

I don't really want to change the third party module, is there any way I can come around this problem and work with the standard library in the project?

R. Martinho Fernandes
  • 228,013
  • 71
  • 433
  • 510
zar
  • 11,361
  • 14
  • 96
  • 178
  • Isn't `errc` part of `std`? That's what namespaces are for. – chris Nov 08 '12 at 16:05
  • 10
    The only thing you should have to change is delete `using namespace std;` from your files. – Praetorian Nov 08 '12 at 16:07
  • yea but poor design/naming by third party module, they have used it which is outside my control – zar Nov 08 '12 at 16:08
  • @Praetorian so I have to use fully qualified names than for stl objects! – zar Nov 08 '12 at 16:09
  • 4
    @zadane, [That's a good thing.](http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-a-bad-practice-in-c) The using statements are scoped as well. – chris Nov 08 '12 at 16:09
  • @zadane: the `std` namespace is there for a reason, and you just found out what that reason is. (You can use selective `using` statements to cut down on the typing.) – Fred Foo Nov 08 '12 at 16:14
  • 2
    Zadane: without changing anything else, try writing std::errc and ::errc in your program and see if that clears up the ambiguity. – David Grayson Nov 08 '12 at 16:14
  • I removed `using namespace std` and it compiles fine now. – zar Nov 08 '12 at 16:22

1 Answers1

1

Don't use in the file

using namespace std;

But you can still include it into functions, say

void f()
{
  using namespace std;

  cout<<endl;
}
Barney Szabolcs
  • 11,846
  • 12
  • 66
  • 91