码迷,mamicode.com
首页 > 其他好文 > 详细

reference to non static member function must be called

时间:2021-06-28 20:58:16      阅读:0      评论:0      收藏:0      [点我收藏+]

标签:word   reference   targe   ring   lambda   静态成员   static   function   passing   

编译器会给类的非静态成员函数添加一个this参数。

int square(int num) {
    return num * num;
}

class Hehe{
    public:
    int square(int num) {
        return num * num;
    }
};

int main() {
    int a = square(2);
    Hehe h;
    int b = h.square(3);
    return 0;
}

006t.gimple

int square (int num)
{
  int D.2396;

  D.2396 = num * num;
  return D.2396;
}


int main ()
{
  int D.2398;

  {
    int a;
    struct Hehe h;
    int b;

    try
      {
        a = square (2);
        b = Hehe::square (&h, 3);
        D.2398 = 0;
        return D.2398;
      }
    finally
      {
        h = {CLOBBER};
      }
  }
  D.2398 = 0;
  return D.2398;
}


int Hehe::square (struct Hehe * const this, int num)
{
  int D.2401;

  D.2401 = num * num;
  return D.2401;
}


x86-64 gcc 11.1

square(int):
        push    rbp
        mov     rbp, rsp
        mov     DWORD PTR [rbp-4], edi
        mov     eax, DWORD PTR [rbp-4]
        imul    eax, eax
        pop     rbp
        ret
Hehe::square(int):
        push    rbp
        mov     rbp, rsp
        mov     QWORD PTR [rbp-8], rdi
        mov     DWORD PTR [rbp-12], esi
        mov     eax, DWORD PTR [rbp-12]
        imul    eax, eax
        pop     rbp
        ret
main:
        push    rbp
        mov     rbp, rsp
        sub     rsp, 16
        mov     edi, 2
        call    square(int)
        mov     DWORD PTR [rbp-4], eax
        lea     rax, [rbp-9]
        mov     esi, 3
        mov     rdi, rax
        call    Hehe::square(int)
        mov     DWORD PTR [rbp-8], eax
        mov     eax, 0
        leave
        ret

https://stackoverflow.com/questions/28746744/passing-capturing-lambda-as-function-pointer

reference to non static member function must be called

标签:word   reference   targe   ring   lambda   静态成员   static   function   passing   

原文地址:https://www.cnblogs.com/Searchor/p/14943952.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!