I have a problem where I want to overload 2 functions by swapping the default parameters to make it possible to swap them in a call.
Create(UncachedGraph* graph, std::string name, Node* parent, std::string path = "", int pos = -1);
Create(UncachedGraph* graph, std::string name, Node* parent, int pos = -1, std::string path = "");
but the problem is that if you call it without passing any arguments to default parameters, the call is ambiguous
Create(this->graph, this->node->getName(), this->node->getParent()); // Create(graph, name, parent) is ambiguous since the overload to be called cannot be resolved
and I understand why it is like that. But I would really love to somehow resolve it by prioritizing one overload over another by some rule, like for example with some "magic qualifier"
prioritized Create(UncachedGraph* graph, std::string name, Node* parent, std::string path = "", int pos = -1);
Create(UncachedGraph* graph, std::string name, Node* parent, int pos = -1, std::string path = "");
which in the above call would resolve the ambiguity by calling the first overload, or something else. The thing is, in this case I simply do not care which of the overloads is being called, because there they are just the same.
So, is there any possible thing I can do to resolve this problem?
but the problem is that if you call it without passing any arguments to default parameters, the call is ambiguous
Well, to resolve ambiguity at least one of the parameters in one of the function declarations must be defined without default:
Create(UncachedGraph* graph, std::string name, Node* parent,
std::string path = "", int pos);
Create(UncachedGraph* graph, std::string name, Node* parent,
int pos = -1, std::string path = "");
The thing is, in this case I simply do not care which of the overloads is being called, because there they are just the same.
You can simply implement the other function with all defaults to call the other one, using parameters in right order:
Create(UncachedGraph* graph, std::string name, Node* parent,
int pos = -1, std::string path = "") {
Create(graph, name, parent, path, pos);
}