Why are opCall's not implicitely assignable?

Karen Lanrap karen at digitaldaemon.com
Sun Sep 24 20:34:55 PDT 2006


Mike Parker wrote:

> Cars have color. These could all be considered object
> properties. Can you name an object that has the property of
> opCall?

Assume we have some colors

  enum COLOR{ LIGHTBLUE, DARKBLUE, RED};

and a car with some colorable parts

  class Car
  {
    Roofliner roof;
    Seat[4] seats;
    Carpet carpet;
    this()
    {
      roof= new Roofs.Handmade;
      seats[0]= new Seats.Handicapped(OVERWEIGHT);
      seats[1]= new Seats.Standard;
      seats[2]= new Seats.Auxiliar(LEFT, TINY);
      // ...

Now I want to assign colors to the colorable parts
  
  Car car;
  void main()
  {
    car= new Car;
    car.roof= COLOR.LIGHTBLUE;
    seats[0]= COLOR.DARKBLUE;
    seats[1]= COLOR.RED
    // ...

But you say that I am not allowed to do this, because the colorable 
parts are no properties of the car?

I have to write

  Car car;
  void main()
  {
    car= new Car;
    with(car)
    {
      roof.color= COLOR.LIGHTBLUE;
      seats[0].color= COLOR.DARKBLUE;
      seats[1].color= COLOR.RED
    // ...

instead? Thereby explicitely saying that I mean the color each time? 

How does this fit with "auto c='c';" implicit type inference? Why do 
I have to write

  COLOR col= seats[0].color;

when it would suffice to write:

  COLOR col= seats[0];

because of appropriate opCalls?

  



More information about the Digitalmars-d-learn mailing list