1 registered members (TipmyPip),
18,546
guests, and 5
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
Re: Possibly Noob help needed on Overload Functions
[Re: DJBMASTER]
#225949
09/06/08 20:53
09/06/08 20:53
|
Joined: Oct 2004
Posts: 1,655
testDummy
Serious User
|
Serious User
Joined: Oct 2004
Posts: 1,655
|
Quoting DJBMASTER. Not sure if this is relevant, but its worth a try. Seems relevant from over here. Nicely done, if it is. Guesses: If Lite-C has a quick STRING* conversion macro (i.e. string() ), 'you' might trying passing char* constants wrapped in that macro. Alternately, you might try to write additional overloaded functions which accept char* constants instead of STRING*. Wait, is there an additional * in each function prototype / definition!? Should ReturnPanel be a pointer to a pointer!? tmpPanel doesn't look like a pointer to a pointer from over here.
//Declares/Prototypes (new)
void PopupMenu(PANEL* ReturnPanel, STRING* SourceData, var layer); //Want to keep this "default" if I can
void PopupMenu(PANEL* ReturnPanel, STRING* SourceData, var layer, var pos_x, var pos_y);
void PopupMenu(PANEL* ReturnPanel, STRING* SourceData, var layer, var pos_x, var pos_y, STRING* font);
void PopupMenu(PANEL* ReturnPanel, char* SourceData, var layer);
void PopupMenu(PANEL* ReturnPanel, char* SourceData, var layer, var pos_x, var pos_y);
void PopupMenu(PANEL* ReturnPanel, char* SourceData, var layer, var pos_x, var pos_y, char* font);
Last edited by testDummy; 09/06/08 21:22.
|
|
|
Re: Possibly Noob help needed on Overload Functions
[Re: DJBMASTER]
#226028
09/07/08 13:20
09/07/08 13:20
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
OP
Expert
|
OP
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Hmm, interesting..... (bing!  !) The snippet you sent works fine, but for some reason Im now thinking of this problem a different way... Multiple times in this thread, people have been finicky about my typecasting, and Ive been shrugging them off as I (mistakenly) believed that the Number-of-params would override typecasting. IE I thought that typecasting is only important IF number of parameters MATCH. Now, after everyones input, Im thinking that the overload will only be run if BOTH type-casts AND Number-of-params Match, if theres no PERFECT match, then first function/prototype is executed, AND if its Number-of-params is wrong, will generate a compile error.So I NOW need to be picky about my type-cast BEFORE compile times. I normally leave typecasting sloppy and fix then once the compile succeeds, but thats been screwing me here. I'll be doing tests on this shortly, and I thank ALL who have contributed to this thread, even if I did not take your advice before, it has finally gotten through my thick skin/Ego. 
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
Re: Possibly Noob help needed on Overload Functions
[Re: EvilSOB]
#226042
09/07/08 14:54
09/07/08 14:54
|
Joined: Feb 2008
Posts: 3,232 Australia
EvilSOB
OP
Expert
|
OP
Expert
Joined: Feb 2008
Posts: 3,232
Australia
|
Finally, thanks to everyones help, Ive got it. Here are the working prototypes for the functions.
//Declares/Prototypes
void PopupMenu(PANEL* ReturnPanel, STRING* SourceData, int layer);
void PopupMenu(PANEL* ReturnPanel, STRING* SourceData, int layer, int pos_x, int pos_y);
void PopupMenu(PANEL* ReturnPanel, STRING* SourceData, int layer, int pos_x, int pos_y, STRING* font); and I dont need to put any typecasting in the calls except for _str() to use char constants. PANEL* NewPanel=NULL;
...
PopupMenu(NewPanel, _str("SendThisAsString"), 1, 100, 200);
... Gives me
......'ReturnPanel' is a pointer to NewPanel,
......'SourceData' is a string containing "SendThisAsString",
......'layer' in an int containing '1',
......'x_pos' in an int containing '100',
......'y_pos' in an int containing '200' Exactly what I wanted, and I now understand fully what I was doing wrong. Another couple of things I leaned today were 1> if you pass a char constant parameter (eg func("xx");) it is converted to string automatically, BUT GETS TREATED AS A CHAR ARRAY for deciding which overload to run. 2> Numeric constant parameters default to "int" in the call (ie func(15); == func((int)15);) but the end function MUST specify that it is expecting an "int". ie func( int InValue ) {...}I hope my problems here are of help to someone else. And once again, thanks to ALL who helped me over this mental block.
"There is no fate but what WE make." - CEO Cyberdyne Systems Corp. A8.30.5 Commercial
|
|
|
|