I need to implement a class with two similar methods, which are overloaded:
class MyClass {
public:
int myMethod(int a) {
// Logic here
}
int myMethod(int b, int c) {
// Logic here
}
};
I want to reuse code and code is very similar for both, I am thinking about creating some generic method and just choose between them in implementation.
class MyClass {
public:
int myMethod(int a) {
myGenericMethod(a, 0, 0);
}
int myMethod(int b, int c) {
myGenericMethod(0, b, c);
}
private:
int myGenericMethod(int a, int b, int c) {
// Full logic is here
}
};
But I am still wondering if this solution is ok. Maybe there is a more elegant solution?