Operators
语法:
1 |
[] |
你可以使用[]操作符访问双向队列中单个的元素。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
//源代码 /** * @brief Subscript access to the data contained in the %deque. * @param n The index of the element for which data should be accessed. * @return Read/write reference to data. * * This operator allows for easy, array-style, data access. * Note that data access with this operator is unchecked and out_of_range * lookups are not defined. (For checked lookups see at().) */ reference operator[](size_type __n) { return this->_M_impl._M_start[difference_type(__n)]; } /** * @brief Subscript access to the data contained in the %deque. * @param n The index of the element for which data should be accessed. * @return Read-only (constant) reference to data. * * This operator allows for easy, array-style, data access. * Note that data access with this operator is unchecked and out_of_range * lookups are not defined. (For checked lookups see at().) */ const_reference operator[](size_type __n) const { return this->_M_impl._M_start[difference_type(__n)]; } |
测试代码:
测试结果:
dq5双向对列:
1 1 1 1 1
请按任意键继续. . .
《双向队列Operators操作符函数运用》上有1条评论
评论已关闭。