Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Static function definition that resembles a pointer to member function

Tags:

c++

I'm looking into the LLVM source code and I never encountered the following syntax:

class BasicBlock {
 public:
  typedef iplist<Instruction> InstListType;
 private:
  InstListType InstList;

  static iplist<Instruction> BasicBlock::*getSublistAccess(Instruction*) {
    return &BasicBlock::InstList;
  }
}

what does the above define? At first it seemed a normal static function but I don't understand the BasicBlock::* part. Seems like a static function which returns a member function pointer and that directly executes that member function's code.

like image 864
Marco A. Avatar asked Nov 17 '25 20:11

Marco A.


1 Answers

The return type of static member function getSublistAccess is

iplist<Instruction> BasicBlock::*

that is, a pointer to a non-static data member of class BasicBlock, where the data type is iplist<Instruction>.

What getSublistAccess actually returns is &BasicBlock::InstList, that is exactly a non-static data member of class BasicBlock, where the data type is InstListType. i.e., iplist<Instruction>.

like image 131
iavr Avatar answered Nov 20 '25 11:11

iavr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!