Slimelite BBS

C++ Problems

Back to EMULATE

From Paul Johnston · 1996-04-09 04:55 · #73577 in EMULATE

Hello All.

I'm fairly at home with C++ now, but have a few problems/queries:

1)
Ok, I've got a class 'Message' and a class 'WriteMsg' derived from this. Now, I want to overload the '=' operator, for Message = WriteMsg But I can't, cause I need to have declared WriteMsg before I can use it in the Message class, but I can't declare WriteMsg before I have declared the Message class. Help :-)

2)
This problem is Windows specific. I have a function (*not* in any class):

BOOL CALLBACK ReadMsgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam);

It is used as a dialog box callback function, and works just fine. Now, I want to have that function as a member of a class. I do it, but the following line:

DlgProc=(FARPROC) &ReadMsg::ReadMsgProc;

brings up a 'cannot cast' error. ie: you can cast the C function like that, but *not* the C++ function. What am I doing wrong?

3)
I have a function which is called several times. It allocated memory for some text (using new). Obviously I don't want to leave all this allocated, and because it needs to remain allocated after the function call, I'd like each call to free the ram allocated by the last call. Obviously if it's safe to free a pointer which should still be NULL, that'd be great - simplify the code loads. Question is... is it safe?

Paul

--- FMail 1.0g
 * Origin: Paul's region of zero area in the plane, Manchester, (2:250/109.38)