開發平台(Platform): (Ex: Win10, Linux, ...)
Linux
編譯器(Ex: GCC, clang, VC++...)+目標環境(跟開發平台不同的話需列出)
GCC
問題(Question):
class Testable {
bool ok_;
typedef void (Testable::*bool_type)() const;
void this_type_does_not_support_comparisons() const {}
public:
explicit Testable(bool b=true):ok_(b) {}
operator bool_type() const {
return ok_ ?
&Testable::this_type_does_not_support_comparisons : 0;
}
};
最近學C++看到這個Safe bool idiom,我知道C++11有其他寫法
可是我想不懂為何裏面都需要加"Testable::"這個,為何一定要寫,
不然編譯不過,不是很懂為何都在class內了還要特別寫,這是哪條規則??
感謝!!
※ 編輯: WangDaMing (39.11.68.163 臺灣), 06/08/2021 19:16:43