struct CCompare
{
const bool operator()(const int& lhs, const int& rhs) const {
return lhs < rhs;
}
};
警告 1 警告 C4180:应用于函数类型的限定符没有意义;
const bool
我在编程书中看到了返回值的用法。当我用vs2010编译上面的代码时,它报告了警告C4180。
相反,以下代码不会导致相同的警告。
struct CCompare
{
bool operator()(const int& lhs, const int& rhs) const {
return lhs < rhs;
}
};
Question1 > const Fundamental_Data_Types
as a function返回值的使用真的没有意义吗?
Question2 > 的用法是真的吗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
}