有没有捷径可以编写具有相同定义但不同原型的函数?

Is there a shortcut to write a function with the same definition but different prototypes?

我有一个 class 的方法,它基本上是这样的:

void MyClass::method() {
    // Here I'm just doing something with parameters which are class attributes
    parameter_3 = parameter_1 + parameter_2
}

我需要另一个具有完全相同主体的方法,但现在我希望通过函数调用传入参数:

void MyClass::method(type1_t parameter_1, type2_t parameter_2);

我不想在另一个定义中重复相同的代码。有哪些可能的解决方案?越丑越好

I need another method which would have exactly the same body, but now I want the parameters to be passed in with the function call:

这可以通过委托来解决。只需从另一个调用一个重载。示例:

void MyClass::method(type1_t parameter_1, type2_t parameter_2) {
    parameter_3 = parameter_1 + parameter_2;
}

void MyClass::method() {
    method(parameter_1, parameter_2);
}