struct CCompare
{
const bool operator()(const int& lhs, const int& rhs) const {
return lhs < rhs;
}
};
Warning 1 warning C4180: qualifier applied to function type has no meaning;
I saw the usage with return value as const bool
in a programming book. When I compiled the above code with vs2010, it reports the warning C4180.
The following code instead will not cause the same warning.
struct CCompare
{
bool operator()(const int& lhs, const int& rhs) const {
return lhs < rhs;
}
};
Question1> Is it true that the usage of const Fundamental_Data_Types
as a function returned value doesn't make sense?
Question2> Is it true that the usage of const Type
as a function returned value only makes sense iff the Type is a class/struct?
Thank you
// Update //
struct CClass
{
int val;
CClass(int _val) : val(_val) {}
void SetValue(int _val) {
val = _val;
}
};
struct CCompare
{
const CClass getMe() const {
return CClass(10);
}
CClass getMeB() const {
return CClass(10);
}
};
int main(/*int argc, char *argv[]*/)
{
CCompare c;
c.getMe().SetValue(20); // error
c.getMeB().SetValue(20); // ok
}