Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does ::* mean in C++?

Tags:

c++

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.

like image 810
Matt Avatar asked Jun 10 '15 21:06

Matt


People also ask

What does &= mean in C?

It means to perform a bitwise operation with the values on the left and right-hand side, and then assign the result to the variable on the left, so a bit of a short form.

What does &variable mean in C?

Variable is basically nothing but the name of a memory location that we use for storing data. We can change the value of a variable in C or any other language, and we can also reuse it multiple times.

What does it mean :: in C++?

In C++, scope resolution operator is ::. It is used for following purposes. 1) To access a global variable when there is a local variable with same name: // C++ program to show that we can access a global variable. // using scope resolution operator :: when there is a local.


2 Answers

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
}
like image 116
Barry Avatar answered Nov 14 '22 05:11

Barry


BOOL (LASreader::*read_simple)();

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

like image 29
R Sahu Avatar answered Nov 14 '22 05:11

R Sahu