Search This Blog

Sunday, November 15, 2009

C++, Argument Type Conversions

Exact Match: (p459, primer)
  • lvalue-to-rvalue conversion: extract lvalue t0 right value
  • array-to-pointer conversion: array is decay to the first element of an array
  • function-to-pointer conversion: function is converted to a pointer to that function
  • qualification conversion: add const or volatile to type pointed by a pointer
Promotion: (p465, primer)
  • convert char, unsigned char, short to type int
  • convert float to double
  • convert enumerator to int, unsigned int, long, or unsigned long
  • convert bool to int
Standard Conversion: (p467 primer)
  • Integral to integral (excluding the promotion) possible loose precision
  • Floating point to floating point (excluding the promotion) possible loose precision
  • Floating integral to integral or integral to floating point possible loose precision
  • integral, floating, enumeration, pointer, to bool
User Define Conversion: (p776 primer)
  • conversion function: operator type() , no return type, no argument, must be a member function. e.g. operator int(), operator double(), operator myType(),
  • constructor conversion: if the argument type matches the argument in the constructor, the constructor can convert the argument to it's own type (i.e. create a temporary using that argument for the constructor). This implicit conversion is not desirable, you can mark the constructor with explicit keyword. This way, to apply the conversion, you need to type the constructor name yourself and pass in the argument. (i.e. cannot omit the constructor name). p. 780

No comments: