Afficher un message
Vieux 09/06/2008, 14h05   #10
Thomas J. Gritzan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Is this void* cast safe?

Gianni Mariani schrieb:
> jason.cipriani@gmail.com wrote:
> ...
>>
>> Again maybe this is a silly question but I've been confusing the heck
>> out of myself staring at this code all day.

>
> Apart from Frank's suggestion, you could use an Any object.
>
> This is the austria "Any" class.
> http://austria.svn.sourceforge.net/v....h?view=markup


...or you could use a variant class (typesafe union), like
boost::variant, which might be a good idea if you have a limited set of
types.

In case of boost::variant, you then could use the visitor pattern to
operate on the object, instead of a chain of if statements.

I think that a 'typesafe union' is more useful than a 'typesafe void*',
because it is easier to work with a fixed set of types. Your code can
only have a limited number of if/else if statements anyway.

--
Thomas
  Réponse avec citation
 
Page generated in 0,04921 seconds with 9 queries