C++ Deque operator =()函数将新内容分配给集合,并替换当前相同类型的内容。双端队列的大小可以相应地修改。
deque& operator(deque& x);
x :这是一个双端队列集合,其内容将被复制到另一个双端队列对象中。
它返回* this。
链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-deque-operator=.html
来源:LearnFk无涯教程网
让我们看一个简单的例子
#include <iostream> #include<deque> using namespace std; int main() { deque<int> a={1,2,3,4,5}; deque<int> b; b.operator=(a); for(int i=0;i<b.size();i++) { cout<<b[i]; cout<<" "; } return 0; }
输出:
1 2 3 4 5
在此示例中,operator =()将'a'集合的内容分配给'b'集合。
让我们看一个简单的例子,当两个双端队列的类型不同时。
#include <iostream> #include<deque> using namespace std; int main() { deque<int> a={10,20,30,40,50}; deque<char> b; b.operator=(a); for(int i=0;i<b.size();i++) { cout<<b[i]; cout<<" "; } return 0; }
输出:
error: no matching function for call to 'std::deque<char>::operator=(std::deque<int>&)'
在此示例中," a"和" b"的类型不同。因此,operator =()函数将引发错误。
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)