C++ 中 ::* 是什么意思?

2024-01-09

什么是

 private:
    BOOL (LASreader::*read_simple)();

mean?

它来自 LAStools,在激光阅读器.hpp https://github.com/LAStools/LAStools/blob/master/LASlib/inc/lasreader.hpp#L132-L133

BOOL is a typedef bool (from mydefs.hpp https://github.com/LAStools/LAStools/blob/master/LASzip/src/mydefs.hpp#L59),但我不知道这一行声明了什么,特别是::*(双冒号星号),并且它看起来像函数调用。


It's a 指向成员函数的指针 http://en.cppreference.com/w/cpp/language/pointer#Pointers_to_member_functions。具体来说,read_simple是一个指向类的成员函数的指针LASreader它接受零个参数并返回一个BOOL.

从 cppreference 中的示例:

struct C {
    void f(int n) { std::cout << n << '\n'; }
};
int main()
{
    void (C::*p)(int) = &C::f; // p points at member f of class C
    C c;
    (c.*p)(1); // prints 1
    C* cptr = &c;
    (cptr->*p)(2); // prints 2
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

C++ 中 ::* 是什么意思? 的相关文章

随机推荐