views:

52

answers:

1

Hi!

I am migrating to OS X and now trying to use Xcode. There is a project that was compiling and running normally on a g++ linux distro, now on mac it is returning a thousand of errors. I guess that the linux std files, somehow included others files needed and now they are not this connected in the std of Mac OS X. How can I know what I am doing wrong, like here:

/Users/Jonathan/Development/C++/Josk/Var.h:257:0 No match for 'operator<<' in 'out << ((Josk::Var*)Jv)->Josk::Var::ToString()' in /Users/Jonathan/Development/C++/Josk/Var.h

the code is:

friend ostream& operator << (ostream &out, Josk::Var &Jv){
  out << Jv.ToString();
return out;
}

I don't know what to add here to solve this, here are the actual includes:

#include <iostream>
#include <ostream>
#include <typeinfo>
#include <map>
#include <utility>
#include <algorithm>

Thanks!
Jonathan

+1  A: 

It looks like you're missing #include <string>.

Kleist
Seems reasonable. `<ostream>` doesn't contain an overload for `operator<<(basic_ostream, basic_string)`. But then I wonder what the return type of `Jv.ToString` is.
Philipp
@Kleist: True, with the include of string, it worked. But How would I know that this specific include would help me? Philipp: ToString returns a const char *.
Jonathan
The reason it works is that std::string has a non-explicit constructor with `const char*` as it's only argument. Which means it's an automatic conversion.I don't know how you would know, apart from making the connection between string and const char*.
Kleist