【总结】connect的研究


1.函数指针

#include <iostream>
using namespace std;
void hello(){
   
    cout<<"abc"<<endl;
}
int abc(int x){
   
    return x+1;
}
typedef void (*pHello)();.........这一行就是typedef的函数指针funcpointer,其实他们就是替代关系,看懂了就
int main(int argc, char *argv[])  好说了,没看懂就觉得很深奥,*pHello就是代替了hello,那么这个指针就应该
{                                 指向hello,*phello=&hello;
    //int (*fAbc)(int axc);
    //fAbc=&abc;
    //cout<<(*fAbc)(1)<<endl;
    void (*pf)();
    pf = &hello;
    //pf = hello;
    (*pf)();
    //pf();
    pHello p = &hello;
    (*p)();
    return 0;
}
/*
typedef int (*pF)(int);     ............这个也是函数指针,这个int必须写上去标明我这里有一个参数。
pF y;                                 其余和上面差不多。
y=&abc;
cout<<(*y)(1)<<endl;
*/
2.成员变量指针
#include <iostream>
using namespace std;
class A{
   
  public:
    int x;
};
void func(A obj, int A::* p){
   //MemberPointer p
    cout<<obj.*p<<endl;
}
void func2(A * obj, int A::* p){
   
    cout<<obj->*p<<endl;
}
template   <class   T>    ...........c++函数模版,根据T类型来决定函数的类型避免重复编程
void func3(T * obj, int T::* p){
   
    cout<<obj->*p<<endl;
}
typedef int A::* MemberPointer;.........成员变量指针  替代关系
int main(int argc, char *argv[])
{
   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值