[vtk-developers] chaining vtk Set... methods

Brad King brad.king at kitware.com
Fri Jan 29 12:03:41 EST 2010


Michael Halle wrote:
>   property->
>     SetColor(1.0, 1.0, 1.0)->
>     SetDiffuse(0.7)->
>     SetSpecular(0.4)->
>     SetSpecularPower(20);

This might work well in interpreted languages that do runtime method
lookup (essentially runtime automatic downcasting).  In C++ though
this will lead to surprises.  See below.

David Gobbi wrote:
> I do like the idea, and I don't think it would cause much trouble with
> debugging, but I'm against it unless it could be made universal.
> There would be nothing worse than having a trick like this that works
> for some Set methods, but not for others.  It would cause much banging
> of heads on desks.

It's worse than that.  If just one of the Set() methods comes from a
superclass then suddenly all of the other Set()s disappear because it
returns a pointer to the superclass:

  struct A { A* SetValueA(int); };
  struct B: public A { B* SetValueB(int); }
  ...
  B* b = new B;
  b->SetValueB(1)->SetValueA(1); // Okay
  b->SetValueA(1)->SetValueB(1); // Error: No "A::SetValueB"

-Brad



More information about the vtk-developers mailing list