【发布时间】:2014-06-27 03:43:09
【问题描述】:
我在阅读有关 C++11 STL 中向量的一些内容时遇到了这段代码。它使用 operator= 的赋值。现在我无法弄清楚它到底做了什么。
代码如下:
namespace std {
template <typename Allocator> class vector<bool, Allocator> {
public:
// auxiliary proxy type for element modifications:
class reference {
...
public:
reference& operator=(const bool ) noexcept; // assignments
reference& operator=(const reference&) noexcept;
operator bool( ) const noexcept; // automatic type conversion to bool
void flip( ) noexcept;
// bit complement
};
...
// operations for element access return reference proxy instead of bool:
reference operator[]( size_type idx );
reference at( size_type idx );
reference front( );
reference back( );
};
}
从上面的代码我可以理解它返回一个类引用类型。但我无法理解的是这个声明reference& operator=(const reference&) noexcept;。
请让我知道这句话在这种情况下的实际含义是什么
【问题讨论】:
-
@Ben:不,它是一个赋值运算符。 en.cppreference.com/w/cpp/language/as_operator
-
@BenjaminLindley 原来如此,谢谢。