CW4.1.6 for Hitachi SuperH - C++ Help

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

CW4.1.6 for Hitachi SuperH - C++ Help

Jump to solution
1,351 Views
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

Labels (1)
Tags (1)
0 Kudos
1 Solution
453 Views
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

View solution in original post

0 Kudos
2 Replies
454 Views
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 Kudos
453 Views
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 Kudos