【发布时间】:2016-09-23 03:18:22
【问题描述】:
如果我有一个返回对数组的引用的成员函数 (https://stackoverflow.com/a/5399014/4304120),我如何向该函数添加 const 限定符?此代码无法在 Visual C++ 2010 下编译。
struct A
{
int data[10];
// this compiles
const int (&f1())[10]
{
return data;
}
// error C2143: syntax error : missing ';' before '<cv-qualifer>'
const int (&f2())[10] const
{
return data;
}
};
【问题讨论】:
-
从C++14开始可以避免
const auto& f2() const { return data; }的问题
标签: c++