Anonymous objects

The objects I don't even care to give a name to

Often used with interface objects (which put a face on data)

Examples
Listen listen_socket(SocketAddr(IPaddress(),Listen_port));

FSMakeFSSpec(0,0,(Pstr)full_path_name,&file_spec);
used in a magical conversion from a Cstr to a Pstr

FilterIt(image). conv(conv_kernel(1,1,1,CommonDenom(3))). clip_to_intensity_range();
void VenusDialog::stop_flight(void)
{
  is_flying = FALSE;
  ModelessDialog::ControlItem(*this,item_Go).
                             set_title("\pGo");
  const int time_elapsed = TickCount() - time_started;	// in Ticks
  NumberItem(*this,item_fps).draw(
   time_elapsed == 0 ? 0 : (60*frame_counter)/time_elapsed );
}


Note

A more advanced example of anonymous objects, which actually do a byte-compilation.



Not only we don't allocate the thing on heap, we don't even assign it a name (nipping possible name conflicts in the bud). No garbage (object garbage/name garbage).

In the FilterIt example: conv_kernel and CommonDenom are classes (not functions). So is FilterIt. And it's all one single statement.



Next | Table of contents