函数指针和回调函数的问题

nofarewell 2012-02-13 02:17:38
请问,C++类里面不能声明函数指针的属性吗?我想用函数指针和回调函数实现一个类似事件的机制。发现可以在类里声明函数指针,为什么类的使用者访问不到这个属性?
...全文
126 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
nofarewell 2012-02-21
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 rabbitlbj 的回复:]

引用 7 楼 nofarewell 的回复:

求救!用了typedef也不行


可以这样使用啊
A为一个类,f是A的一个成员函数

typedef void (A::*m_pFunc)();

A a;
m_pFunc m = &A::f;
(a.*m)();
[/Quote]
还没试你的方法。之前我自己解决了。分给你
RabbitLBJ 2012-02-14
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 nofarewell 的回复:]

求救!用了typedef也不行
[/Quote]

可以这样使用啊
A为一个类,f是A的一个成员函数

typedef void (A::*m_pFunc)();

A a;
m_pFunc m = &A::f;
(a.*m)();
程序员小迷 2012-02-14
  • 打赏
  • 举报
回复
c++中没有属性啊
nofarewell 2012-02-13
  • 打赏
  • 举报
回复
问题已解决,可以用声明委托再转为函数指针的办法
nofarewell 2012-02-13
  • 打赏
  • 举报
回复
求救!用了typedef也不行
nofarewell 2012-02-13
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 czh3642210 的回复:]

在类构造函数里边注册一下。。。
[/Quote]
构造函数注册了,好像在C#里识别不出这个参数。C++类编译可以通过,C#构造类的进修,提示参数列表错误
W170532934 2012-02-13
  • 打赏
  • 举报
回复
void (*p_end_process)(unsigned char* ibuf, unsigned char* obuf);这地方是不是还缺了个typedef???
面包大师 2012-02-13
  • 打赏
  • 举报
回复
在类构造函数里边注册一下。。。
nofarewell 2012-02-13
  • 打赏
  • 举报
回复
块明如下:

#include "jpegtoyuv.h"

#pragma once
namespace H264Lib
{
public ref class H264Encoder
{
public:
H264Encoder();
H264Encoder(unsigned char *ibuf, unsigned char *obuf, unsigned int img_width, unsigned int img_height, unsigned int total_frames, unsigned int fps);
~H264Encoder();
public:
void Jpeg2Yuv(unsigned char *jpegdata, int jpegsize, unsigned int width, unsigned int height, unsigned char *ibuf);
void Encode();
int test();
protected:
void init();
public:
void (*p_end_process)(unsigned char* ibuf, unsigned char* obuf);
unsigned char *ibuf;
unsigned char *obuf;
int ibuf_index;
int obuf_index;
int *r_f;
int *w_f;
unsigned int img_width;
unsigned int img_height;
unsigned int fps;
unsigned int total_frames;
};
}
nofarewell 2012-02-13
  • 打赏
  • 举报
回复
是公有的 不过这个类是编译成/CLR 托管的,在C#下引用
bdmh 2012-02-13
  • 打赏
  • 举报
回复
怎么访问不到,你怎么声明,是不是私有属性

64,654

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧