POV-Ray : Newsgroups : povray.off-topic : new C# stuff : Re: new C# stuff Server Time
6 Sep 2024 17:19:29 EDT (-0400)
  Re: new C# stuff  
From: Darren New
Date: 22 Jan 2009 15:44:14
Message: <4978da9e$1@news.povray.org>
Warp wrote:
>   The benefit is that, at least in theory, the member function can be
> dynamically bound, while the regular function can't.

But not on an object that only occupies four bytes, which is your usual 
example. :-)

>   Although in some situations it could make a difference also with static
> member functions, regarding to access rights. For example, a member
> function of a derived class can access the functions in the protected
> part of the base class, but an regular function can't. (Making the regular
> function a friend of the base class would open even the private part of
> it, which might not be what you want.)

C# also has an assembly-level rights declaration. So instead of friends, you 
declare the things you want befriended "internal". So for example, the link 
pointers in a linked list cell can be tagged "internal", which basically 
means any other classes in the same DLL can access them[1].

>> Because it looks like it's part of the class. You don't have to remember 
>> which members are built in and which ones were added by a library you're using.
> 
>   One could maybe argue that that's a *bad* thing. If it looks like part
> of the class but isn't, that might cause problems when you reuse the class
> somewhere else, where you might not have the extension in question.

It isn't defined as part of the class. That's kind of the point. It's 
declared[2] only where you import it. Hence, you can make such an extention 
for your code, and I can make one for my code, and it doesn't conflict 
unless I want to use both, at which point I fall back to the 
fully-namespace-qualified form of the call. Unless I import the module 
defining the function, the function isn't visible as a pseudo-member.




Incidentally, you can also declare something as a "partial member function" 
in a class, which gives it a declaration but not a definition. If you never 
define it, calls to it act like they are just empty functions (i.e., they 
have no effect). If you do define it, then the function gets called. (I 
haven't really followed this up much, but I'm guessing it has to be a void 
function, and I'm not sure how this is helpful in the given environment, but 
it's not the sort of thing you put in without a use case in mind. :-)

This is distinct from a "partial class", where the code (and declarations) 
for one class are split across multiple source files.



[1] Lies-to-children. It's a bit more complicated than that, but that's the 
basics of it.
[2] ...to use the terminology of C here distinguishing declare/define.
-- 
   Darren New, San Diego CA, USA (PST)
   "Ouch ouch ouch!"
   "What's wrong? Noodles too hot?"
   "No, I have Chopstick Tunnel Syndrome."


Post a reply to this message

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