Optional String parameter?

Started by RickJ, Fri 17/03/2006 10:39:17

Previous topic - Next topic

RickJ

How do I make a String parameter optional as shown below?   

// Module Script
struct WinBlu  {
   // Some stuff
   // :

   import static String   Data(String Name, String Value=null);

   // Some more stuff
   // :
};

When I set it equal to null or to ""  I get the error below.  If I set it to zero
the compiler is happy but I don't think that is right either.   

Error (line xxx): Parameter default value must be literal

I assume I am missing something really obvious here;  it makes me feel so damm noobish.    := 

Pumaman

You can only have optional parameters for int and float parameters.

RickJ

Whew, I feel way better now.  ;)  Thanks ...

monkey0506

CJ you are no fun.  You can set it to 0 to make it optional (as you already figured out) and then in the function just pretend as if it's null...it works in any case.  You know me...I'm not big on "conventional."

RickJ

Generally speaking null is not necessarily guaranteed to be equal to 0 for all situations for all time.  If it were, there  wouldn't need to be a keyword for it. 


monkey0506

#5
Well actually I think the keyword is just something of a simplification.  Kind of like the enumerated bool value "false".  It's equal to 0 and unless some major failure of logic takes place in the near future, it always will be.

I understand the concern about using 0 instead of null and whatever...but...

Quote from: meI'm not big on "conventional.

[EDIT:]

Oh...and I think it's worthy of mentioning that enumerated values (including bool) are handled internally as an integral type, so they can be optional as well.

SMF spam blocked by CleanTalk