
-----------------------------------
wtd
Sun Jul 02, 2006 3:33 pm

Value of const/final members in classes?
-----------------------------------
So... what's your opinion?  Do constant or final (in the case of Java and some others) members (or "instance variables") have merit? 

Or should this be purely enforced by the methods a classes exposes?

-----------------------------------
[Gandalf]
Sun Jul 02, 2006 11:03 pm


-----------------------------------
They're useful for internal use inside a class, no?  For constants which you must access externally, I'd use methods.

-----------------------------------
wtd
Mon Jul 03, 2006 4:16 pm


-----------------------------------
I was actually thinking of just the opposite.

Consider:

class Foo
{
   private:
      int _bar;
 
   public:
      Foo(int b) : _bar(b) { }

      int bar() const
      {
         return _bar;
      }
};

vs.

struct Foo
{
   const int bar;

   Foo(int b) : bar(b) { }
};
