POV-Ray : Newsgroups : povray.programming : cleaning source code from warnings troubles : Re: cleaning source code from warnings troubles Server Time
28 Jul 2024 14:27:02 EDT (-0400)
  Re: cleaning source code from warnings troubles  
From: Warp
Date: 4 Oct 2002 07:47:43
Message: <3d9d7fdf@news.povray.org>
Christopher James Huff <chr### [at] maccom> wrote:
> I do use "struct" instead of "class" to differentiate these...there is 
> no real difference to the compiler other than default access level, but 
> you will never see a class from me with a public variable. (unless it is 
> something left over from debugging or some coding mistake)

  Yes, if you want a conglomeration of values (ie. a type which contains
several variables inside it), use struct instead of class.
  In these cases it's ok. However, if it would contain more than four or
five values, then you might want to think about abstracting it.

  A good(?) example of this usage is the 'pair' struct in the standard
library.

> Off the topic of this discussion, but another thing I've occasionally 
> wished for was a way to specify specific methods as being exposed to 
> objects of a class...friend classes are close, but are all-or-nothing. 

  I have sometimes wished this too. It would certainly be useful if you
could say "class A can access this private method of this class B, but
nothing else".
  I can imagine an easy syntax for this as well. Something like:

class B
{
 private:
    void foo() friend A;
};

  (If you want more than one class to have access to the method, you could
just list them separated with commas after the 'friend' keyword.)


>> > And I've never used the "?:" operator.
>>   Why not? It's handy. :)

> Never needed it. Expressions using it are much less readable IMO, and 
> I've never had a situation where using if...else was significantly 
> longer or more awkward.

  I don't use it often, but sometimes it's handy. For example:

cout << "The switch 1 is " << (switch1 ? "on" : "off") << endl;

  I think that's quite readable, and less cluttered than:

cout << "The switch 1 is ";
if(switch1) cout << "on";
else cout << "off";
cout << endl;

-- 
#macro M(A,N,D,L)plane{-z,-9pigment{mandel L*9translate N color_map{[0rgb x]
[1rgb 9]}scale<D,D*3D>*1e3}rotate y*A*8}#end M(-3<1.206434.28623>70,7)M(
-1<.7438.1795>1,20)M(1<.77595.13699>30,20)M(3<.75923.07145>80,99)// - Warp -


Post a reply to this message

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