POV-Ray : Newsgroups : povray.off-topic : C# 4.0 Default parameters : Re: C# 4.0 Default parameters Server Time
6 Sep 2024 15:20:25 EDT (-0400)
  Re: C# 4.0 Default parameters  
From: Warp
Date: 4 Feb 2009 14:11:45
Message: <4989e870@news.povray.org>
Darren New <dne### [at] sanrrcom> wrote:
>    class Thing {
>      static public int pdq(float y) { ... }
>      public abc(float z) { return (int) (z*this.stuff); }
>      int stuff;
>      Thing() { stuff = 28; }
>    }

>    Thing o = new Thing();
>    delegate int xyz(float x);
>    xyz = Thing.pdq;
>    xyz += o.abc;
>    xyz(27.3);  //  I think this will return the result of calling o.abc(27.3)

> Pretty handy.

  What if you want to call the function (through the pointer) for different
objects? I mean like you would write in C++:

    Object obj1, obj2;
    obj1.*funcPtr(param);
    obj2.*funcPtr(param);

  The same member function is called, but for different objects. (Thus if
the function in question eg. changes the state of the object, it happens
to the specified object.)

  Curiously, you can even have pointers-to-member-variables in C++, and you
can then dereference the pointer on a per-object basis. That gets pretty
confusing pretty quick.

-- 
                                                          - Warp


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.