When I first compiled my C ++ code using GCC 4.3 (after he compiled it successfully without warnings on 4.1, 4.0, 3.4 with the -Wall -Wextra ), I unexpectedly got a bunch of warning: type qualifiers ignored on function return type .
Consider temp.cpp :
class Something { public: const int getConstThing() const { return _cMyInt; } const int getNonconstThing() const { return _myInt; } const int& getConstReference() const { return _myInt; } int& getNonconstReference() { return _myInt; } void setInt(const int newValue) { _myInt = newValue; } Something() : _cMyInt( 3 ) { _myInt = 2; } private: const int _cMyInt; int _myInt; };
Running g++ temp.cpp -Wextra -c -o blah.o :
temp.cpp:4: warning: type qualifiers ignored on function return type temp.cpp:7: warning: type qualifiers ignored on function return type
Can someone tell me what I'm doing wrong that violates the C ++ standard? I believe that when returning by value, the leading const superfluous, but it's hard for me to understand why it needs to create a warning. Are there other places where I should leave const?
c ++ const gcc-warning
Seth Johnson Jul 15 '09 at 21:38 2009-07-15 21:38
source share