我正在尝试使用 GCC 编译器编译以下代码
class Class
{
public:
uInt16 temp;
const uInt32 function() const;
}
inline const uInt32 class::function() const
{
return temp;
}
Run Code Online (Sandbox Code Playgroud)
我收到以下编译器警告
警告:在函数返回类型 [-Wignored-qualifiers] 上忽略类型限定符
有什么想法可以解决这个警告吗?
简单地使用:
uInt32 function() const;
Run Code Online (Sandbox Code Playgroud)
返回 const 原始类型是无用的,因为c.function()++即使没有const.
返回 const 对象用于模仿与上述类似的原语和禁止代码,但现在(自 C++11 起),如果需要,我们可以干净地禁止:
struct S
{
S& operator ++() &;
S& operator ++() && = delete;
};
S f(); // Sufficient, no need of const S f() which forbids move
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1402 次 |
| 最近记录: |