English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
C++ Deque (Double-ended Queue)
C ++ The Deque operator =() function allocates new content to the container and replaces the current content of the same type. The size of the deque can be modified accordingly.
deque& operator(deque& x);
x:This is a deque container whose content will be copied to another deque object.
It returns* this.
Let's look at a simple instance
#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; }
Output:
1 2 3 4 5
In this example, the operator =() assigns the content of the 'a' container to the 'b' container.
Let's look at a simple example when two dequeues are of different types.
#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; }
Output:
error: no matching function for call to 'std::deque<char>::operator=(std::deque<int>&)'
In this example, the types of 'a' and 'b' are different. Therefore, the operator =() function will throw an error.