C++ – How to Overload a Function with the Same Type Parameter

ccoding-styleoverloadparametersqt

I'm creating an API, and I want to overload a function for strip:

QString MyClass::strip();
QString MyClass::strip(QRegularExpression open);
QString MyClass::strip(QRegularExpression close);
QString MyClass::strip(QRegularExpression open, QRegularExpression close);

Obviously the second and third conflict.

What is the recommended style for C++ and Qt programmers to restructure this?

Best Answer

What about creating a class to hold your arguments? This class would contain both open and close parameters and either of them could be NULL. Then, there will be only one strip method with above class as argument and method will decide if it wants to use open/close if they are set.

Related Topic