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

Michael Halle mhalle at bwh.harvard.edu
Fri Jan 29 15:11:04 EST 2010


Sigh.

Thanks Brad.

--Mike



On 1/29/10 12:03 PM, Brad King wrote:
> 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
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtk-developers
>




More information about the vtk-developers mailing list