您可以通过__func__(C99)或__FUNCTION__或__PRETTY_FUNCTION__(非标准).
如果调用者没有提供__func__(假设内联函数,所有符号都被剥离),则没有标准且可靠的方法来查找函数调用者的名称.
但是如果困扰你的话,最好将公共部分重构成一个独立的功能.
int compare(const T& other) const { ... }
bool operator< (const T& other) const { return compare(other) < 0; }
bool operator> (const T& other) const { return compare(other) > 0; }
...
Run Code Online (Sandbox Code Playgroud)