I have a make() static method in a class Response. It is overloaded to take either std::string or Json::Value from jsoncpp.
I overloaded the method to look like this:
Response::make(Json::Value body)
{
...
}
Response::make(std::string body)
{
...
}
This causes this error on compilation:
more than one instance of overloaded function "Response::make" matches the argument list:C/C++(308)
main.cpp(15, 20): function "Response::make(std::string body)" (declared at line 28 of "/home/user/weasle/./weasel/./Response.h")
main.cpp(15, 20): function "Response::make(Json::Value body)" (declared at line 36 of "/home/user/weasle/./weasel/./Response.h")
main.cpp(15, 20): argument types are: (const char [33])
Is Json::value treated as a string? How can I fix this issue?
main. -- How do I correctly overloaded methods -- The issue probably has nothing to do with this. It may have everything to do with how you are calling the function.Response::make(Json::Value body)is an invalid C++ code.makewith some string literal as argument. Which of the two overloads do you expect to be used for this? Both can make sense. So maybe overloading isn't the correct approach in this case at all.Jason::Valuehas a constructor that accepts aconst char *. So doesstd::string. Callingsome_response.make("string literal")will mean that conversions tostd::stringandJson::Valueare both equally viable, hence the ambiguity. You need to either remove or rename one of your overloads ofmake(), or force the conversion e.g.some_response.make(std::string("string literal"))orsome_response.make(Json::Value("string literal"))to remove the ambiguity at the call site.