Board index » cppbuilder » Direct draw surface as a function argument.

Direct draw surface as a function argument.


2005-04-05 06:43:14 PM
cppbuilder5
Hello,
Is it possible to pass a direct draw surface as a default parameter in a function, something like this?
LPDIRECTDRAWSURFACE lpDDSFont;
void PrintNum(String num, String align, int destx, int desty,
LPDIRECTDRAWSURFACE lpDDSLetters = lpDDSFont,
DWORD TRANS=DDBLTFAST_SRCCOLORKEY);
In my last parameter the default value is working well, but for
the direct draw surface the compliler says "lpDDSFont can't be
used without an object".
 
 

Re:Direct draw surface as a function argument.

"kvsgs" < XXXX@XXXXX.COM >wrote in message
Quote
In my last parameter the default value is working well, but
for the direct draw surface the compliler says "lpDDSFont
can't be used without an object".
Please show a more complete code snippet that shows how PrintNum() is being
called. The error suggests that your variable is a member of a class but
PrintNum() is not. If PrintNum() is not a member of a class, then you
cannot use class members as default parameters. Your lpDDSLetters pointer
would have to be a global variable. Otherwise, PrintNum() must be a member
of a class in order to access class members.
Gambit
 

Re:Direct draw surface as a function argument.

Quote
Please show a more complete code snippet that shows how
PrintNum() is being called.
Here is my class declaration:
class TLVegas : public TForm
{
private:
(...)
LPDIRECTDRAWSURFACE lpDDSFont;
void PrintNum(String num, String align, int destx, int desty,
LPDIRECTDRAWSURFACE lpDDSLetters = lpDDSFont,
DWORD TRANS=DDBLTFAST_SRCCOLORKEY);
}
Here is PrintNum definition:
void TLVegas::PrintNum(String num, String align, int destx, int
desty, LPDIRECTDRAWSURFACE lpDDSLetters,DWORD TRANS)
and an example of a call:
PrintNum(IntToStr(a) , "L", 545, 525);
PrintNum(IntToStr(b) , "L", 56, 50, lpDDSFont);
The second call wokrs well if I remove the LPDIRECTDRAWSURFACE
lpDDSLetters = lpDDSFont in PrintNum definition and leave only
LPDIRECTDRAWSURFACE lpDDSLetters without a defalut value.
The first call,is how I want to be able to call the function,
but it doesn't work because the compiler finds the above
error:
[C++ Error] LasVegas.h(101): E2231 Member TLVegas::lpDDSFont
cannot be used without an object
I can't understand.
 

{smallsort}

Re:Direct draw surface as a function argument.

"kvsgs" < XXXX@XXXXX.COM >wrote in message
Quote
Here is my class declaration:
<snip>
I would suggest the following alternative approach:
class TLVegas : public TForm
{
private:
//...
LPDIRECTDRAWSURFACE lpDDSFont;
void PrintNum(const AnsiString &num, const AnsiString &align, int
destx, int desty, LPDIRECTDRAWSURFACE lpDDSLetters = NULL, DWORD TRANS =
DDBLTFAST_SRCCOLORKEY);
};
void TLVegas::PrintNum(const AnsiString &num, const AnsiString &align,
int destx, int desty, LPDIRECTDRAWSURFACE lpDDSLetters, DWORD TRANS)
{
if( NULL == lpDDSLetters )
lpDDSLetters = lpDDSFont;
//...
}
PrintNum(a, "L", 545, 525);
PrintNum(b, "L", 56, 50, lpDDSFont);
Gambit