c++ 成员函数可以传递this指针给普通函数

#include<iostream>


class Test;
void fun(Test *t);


class Test{
public:
    int a;
    int b;
    void call()
        {
            fun(this);
        }
};

void fun(Test *t)
{

    printf(" t->a:=%d ", t->a);
}


int main(int argc, char *argv[])
{
    Test test;
    test.a = 1;
    test.b = 2;

    test.call();
    
    return 0;
}

猜你喜欢

转载自blog.csdn.net/u010029439/article/details/82225984
今日推荐