1

I have project that is compiled without any problem. I have added two lines to one of its cpp files:

#include <boost/log/trivial.hpp>
using namespace std;

And got a lot of error related to xxresult unit:

Error   14  error C2825: '_Fty': must be a class or namespace when followed by '::' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult 28
Error   15  error C2903: 'result' : symbol is neither a class template nor a function template  C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult 28
Error   16  error C2039: 'result' : is not a member of '`global namespace'' C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult 28
Error   17  error C2143: syntax error : missing ';' before '<'  C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult 28
Error   18  error C2039: 'type' : is not a member of '`global namespace''   C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult 28
Error   19  error C2238: unexpected token(s) preceding ';'  C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult 28
Error   20  error C2039: '_Type' : is not a member of 'std::tr1::_Result_type2<__formal,_Fty,_Arg0,_Arg1>'  C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult 40
Error   21  error C2146: syntax error : missing ';' before identifier '_Type'   C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult 40
Error   22  error C4430: missing type specifier - int assumed. Note: C++ does not support default-int   C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult 40
Error   23  error C2602: 'std::tr1::_Result_of2<_Fty,_Farg0,_Farg1>::_Type' is not a member of a base class of 'std::tr1::_Result_of2<_Fty,_Farg0,_Farg1>'  C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult 40
Error   24  error C2868: 'std::tr1::_Result_of2<_Fty,_Farg0,_Farg1>::_Type' : illegal syntax for using-declaration; expected qualified-name C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\xxresult 40
Error   25  error C2678: binary '!=' : no operator found which takes a left-hand operand of type 'std::tr1::_Bind_fty<_Fty,_Ret,_BindN>' (or there is no acceptable conversion) C:\Projektai\fbSrv_2010\serv.cpp    70

How boost is related with std and how to start solve such errors?

JDługosz
  • 5,592
  • 3
  • 24
  • 45
vico
  • 17,051
  • 45
  • 159
  • 315
  • I think that if you remove `using namespace std;` then it should compile. – psur Nov 21 '14 at 09:57
  • yes, but why? It is very common to use std and boost in the same unit – vico Nov 21 '14 at 09:58
  • 1
    @vico, you should avoid adding "using namespace std;" in your code. [It is bad practice](http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice) because it imports all symbols defined in the std namespace, indiscriminately (and causes problems such as this one). – utnapistim Nov 21 '14 at 10:03
  • 1
    It is only common to use 'using namespace std' in example programs. – Pete Nov 21 '14 at 10:03
  • @vico: Of course you can use both. You just shouldn't pollute the global namespace with the contents of either library; they are in their own namespaces for good reason, to prevent name conflicts. See http://stackoverflow.com/questions/1452721 – Mike Seymour Nov 21 '14 at 10:03
  • Go here: **[Q: Why is “using namespace std;” considered bad practice?](http://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice)** – sehe Nov 21 '14 at 10:42

0 Answers0