我在说什么?

The*_* do 0 c++

有没有办法检查fnc这个fnc名称是什么?我目前正在使用LargeInt类,我已经意识到oparator>和operator <的代码几乎相同,所以我想知道运算符是在调用我并做出相应的反应.
谢谢.

ken*_*ytm 6

您可以通过__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)