18

What does

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

mean?

It's from LAStools, in lasreader.hpp

BOOL is a typedef bool (from mydefs.hpp), but I don't know what this line is declaring, specifically the ::* (double colon asterisk), and that it looks like a function call.

Matt
  • 1,928
  • 24
  • 44
  • 12
    pointer to member. – T.C. Jun 10 '15 at 21:03
  • Like an alias to a method? Because there's no member (variable nor method) named `read_simple` on this class. The CPP for this header does use a variable named `read_simple`, but I don't see any declaration for it. And this class doesn't extend anything.. maybe I'm just missing something – Matt Jun 10 '15 at 21:07
  • 1
    related post : https://stackoverflow.com/questions/670734/c-pointer-to-class-data-member – coincoin Jun 10 '15 at 21:09

2 Answers2

18

It's a pointer to member function. Specifically, read_simple is a pointer to a member function of class LASreader that takes zero arguments and returns a BOOL.

From the example in the 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
}
Barry
  • 286,269
  • 29
  • 621
  • 977
  • Thanks! Now I just have to figure out why they're doing this. :) That member points at a pure virtual member function. – Matt Jun 10 '15 at 21:18
  • 2
    @Matt Nothing wrong with that. When you call it with an instance, it'll still go through the same virtual dispatch process. – Barry Jun 10 '15 at 21:43
4
BOOL (LASreader::*read_simple)();

read_simple is a pointer to a member function of class LASreader that takes no arguments and returns a BOOL.

R Sahu
  • 204,454
  • 14
  • 159
  • 270