RE: [Plib-devel] PLIB developers needed.
Brought to you by:
sjbaker
From: Dave M. <Dav...@dy...> - 2000-08-10 17:23:13
|
Steve wrote: > I tried to compile PLIB on an SGI machine at work - and your > 'const-ification' of the clock > routine stopped it from compiling on the IRIX compiler. > > You had: > > class ulClock > { > ... > public: > ... > int getSomething () const { return something ; } > ... > } ; > > The 'const' seemed to do *bad* things to the SGI compiler. > > Could you remind me what exactly a 'const' right there > actually *does*? > > ...and then remove them anyway! > I use 'const' in only two ways: 1) const data -- const Type* foo ; 2) const method -- Type getSomething () const ; #1 means you can't change what foo points to. You already use this heavily in SG. #2 means that the class method getSomething cannot change its instance. it is commonly used for inline 'query' methods. #1 and #2 are often used together. for example, if you write a function like this: void checkfoo ( const Type* foo ) { return ( foo -> getSomething () == 42 ) ; } if getSomething() is not a 'const' method then you get a warning because it thinks you are changing what foo points to. the alternative is casting away the 'const' of foo ala ((Type*)foo) which is not as clear. I really thought 'Type getSomething () const' was a very portable and standard idiom. Could you check the SGI documentation on that? If needed, I will remove the 'const' methods as you advise. --Dave |