struct CCompare { const bool operator()(const int& lhs, const int& rhs) const { return lhs < rhs; } };
Warning 1 warning C4180: a qualifier applied to a function type does not have that is;
I saw use with return value as const bool in a programming book. When I compiled the above code with vs2010, it reports C4180 warning.
The following code will not lead to the same warning instead.
struct CCompare { bool operator()(const int& lhs, const int& rhs) const { return lhs < rhs; } };
Question1 Is it true that using const Fundamental_Data_Types as the return value of a function does not make sense?
Question2 Is it true that using const Type as the return value of a function makes sense if Type is a / struct class?
thanks
// 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() { CCompare c; c.getMe().SetValue(20);
q0987 source share