CW4.1.6 for Hitachi SuperH - C++ Help

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

CW4.1.6 for Hitachi SuperH - C++ Help

跳至解决方案
2,187 次查看
eski
Contributor I

Hi,
I am using Codewarrior for Hitachi SuperH ver 4.1.6 build 0672.

I know it is an old version but i write software for casio machines and this is the one they use .

I face a problem with C++ syntax:
I do use delphi to write my software and i wrote a converter to convert pascal to C , everything works fine since years.
I face a problem with class method pointers , in delphi we can have variable which are class method pointers declared as " TOnClick = Procedure (Sender:TQtControl) of object;"
i translate this to :
typedef void (_tobject::*uonclick)(tqtcontrol *sender);
typedef struct {
_tobject *obj;
uonclick event;
}tonclick;

I do have declared class variable of that type
tonclick fonclick;

I do initialize the variable with
b->fonclick.obj=this;
b->fonclick.event=(uonclick)onlevelclick;

This declaration works fine with Visual C++ 6.0 but when i compile it with code warrior i get :
Warning : illegal implicit member pointer conversion
_qtcore.CPP line 1602 b->fonclick.event=(uonclick)onlevelclick;

--
Alban Edit: Mention product name in subject line.

Message Edited by Alban on 2007-03-20 05:48 PM

标签 (1)
标记 (1)
0 项奖励
回复
1 解答
1,289 次查看
CompilerGuru
NXP Employee
NXP Employee
One topic Lundins link does not mention is that pointer to members have a non intuitive conversion
behavior. With normal pointers, you can easily assign a pointer to a derived class to a pointer to the base class. With pointer to members its just the opposite. You can assign a pointer to a member of a base class to any pointer to member expecting a derived class, well, a bit hard to describe. In the end, a pointer to a member function can only point to any member function of the class it refers to, it is not possible to add new functions in derived classes and initialize the pointer to member with them (unless they overwriting a virtual function already existing in the base).

Daniel
See also:

http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/index.jsp?topic=/com.ibm.vacpp6m.doc/languag...

Message Edited by CompilerGuru on 2007-03-2106:09 PM

在原帖中查看解决方案

0 项奖励
回复
2 回复数
1,290 次查看
CompilerGuru
NXP Employee
NXP Employee
One topic Lundins link does not mention is that pointer to members have a non intuitive conversion
behavior. With normal pointers, you can easily assign a pointer to a derived class to a pointer to the base class. With pointer to members its just the opposite. You can assign a pointer to a member of a base class to any pointer to member expecting a derived class, well, a bit hard to describe. In the end, a pointer to a member function can only point to any member function of the class it refers to, it is not possible to add new functions in derived classes and initialize the pointer to member with them (unless they overwriting a virtual function already existing in the base).

Daniel
See also:

http://publib.boulder.ibm.com/infocenter/macxhelp/v6v81/index.jsp?topic=/com.ibm.vacpp6m.doc/languag...

Message Edited by CompilerGuru on 2007-03-2106:09 PM

0 项奖励
回复
1,289 次查看
Lundin
Senior Contributor IV
You can't take the address from non-static member functions. Read all of this:

http://www.parashift.com/c++-faq-lite/pointers-to-members.html#faq-33
0 项奖励
回复