Christian Holm Christensen wrote: > Hi Peter & all, > > On Wed, 7 Jun 2000 13:54:19 +0200 (CEST) "Peter H. L. Christiansen" <pchristi@nbi.dk> wrote: > > I can make the warning go away by adding either : > > Char_t* GetFileName() const {return (Char_t*) fFileName;} or > > const Char_t* GetFileName() const {return fFileName;} > > the first one should propably use one of the specific casting operators > > instead of the general one. > > No! The first one is actually the closest to being the right one. Why > I hear you say?! Well, "GetFileName()" should be "const" because the > method shouldn't change any variables or members, further it should > return "const Char_t*", since that's the type of fFileName Christian, Here is the 64 cent question why is fFileName const? It is not declared as such explicitly e.g. Char_t is just char - is it because of the explicit decalration of [256] ? Other wise I agree in conclusions. > One could > even argue that it should return "const Char_t* const" since the user > shouldn't even be allowed to change the address/value of the returned > pointer, but that may be too strict. Hence the prober inline code > would be: > > const Char_t* GetFileName(void) const { return fFileName; } > > or even > > const Char_t* const GetFileName(void) const { return fFileName; } > > For more on keyword "const" and pointers refer to section 8.3.1 in the ISO > C++ standard. > > Cheers, > > Christian ----------------------------------------------------------- > Holm Christensen Phone: (+45) 35 35 96 91 > Sankt Hansgade 23, 1. th. Office: (+45) 353 25 305 > DK-2200 Copenhagen N Web: www.nbi.dk/~cholm > Denmark Email: cholm@nbi.dk
This archive was generated by hypermail 2b29 : Wed Jun 07 2000 - 12:17:55 EDT