Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Value of const/final members in classes?
Index -> General Programming
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
wtd




PostPosted: Sun Jul 02, 2006 3:33 pm   Post subject: 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?
Sponsor
Sponsor
Sponsor
sponsor
[Gandalf]




PostPosted: Sun Jul 02, 2006 11:03 pm   Post subject: (No subject)

They're useful for internal use inside a class, no? For constants which you must access externally, I'd use methods.
wtd




PostPosted: Mon Jul 03, 2006 4:16 pm   Post subject: (No subject)

I was actually thinking of just the opposite.

Consider:

code:
class Foo
{
   private:
      int _bar;
 
   public:
      Foo(int b) : _bar(b) { }

      int bar() const
      {
         return _bar;
      }
};


vs.

code:
struct Foo
{
   const int bar;

   Foo(int b) : bar(b) { }
};
Display posts from previous:   
   Index -> General Programming
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 3 Posts ]
Jump to:   


Style:  
Search: