<分区>
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;
我在一本编程书上看到返回值为const bool
的用法。我用vs2010编译上面的代码,报C4180警告。
下面的代码不会引起同样的警告。
struct CCompare
{
bool operator()(const int& lhs, const int& rhs) const {
return lhs < rhs;
}
};
问题 1> const Fundamental_Data_Types
作为函数返回值的用法真的没有意义吗?
问题 2> 如果 Type 是一个类/结构,使用 const Type
作为函数返回值是否真的有意义?
谢谢
//更新//
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
}