哪个容器类可以用=赋值?

yueyucanyang 2008-11-12 02:46:37
哪个容器类可以用=赋值?,我使用deque不可以赋值,但是vector好像可以,但是MSDN为什么没有呢?还有别的容器类可以用=赋值吗?
...全文
111 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
qq675927952 2008-11-13
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 healer_kx 的回复:]
从来不用=,看着害怕。
[/Quote]

是啊,这和深复制和 浅复制有关,尽量自己写 代码
jackzhhuang 2008-11-13
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 healer_kx 的回复:]
从来不用=,看着害怕。
[/Quote]
同感
yueyucanyang 2008-11-13
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 hityct1 的回复:]
有赋值号:
deque <T,Allocator>& operator= ( const deque <T,Allocator>& x );

C/C++ code
#include <iostream>
#include <deque>
using namespace std;

int main ()
{
deque<int> first (3); // deque with 3 zero-initialized ints
deque<int> second (5); // deque with 5 zero-initialized ints

second=first;
first=deque<int>();

cout << "Size of first: " << int (first.siz…
[/Quote]

在我这里编译不过去啊!~
yshuise 2008-11-12
  • 打赏
  • 举报
回复
stl -> all
hityct1 2008-11-12
  • 打赏
  • 举报
回复
有赋值号:
deque<T,Allocator>& operator= ( const deque<T,Allocator>& x );

#include <iostream>
#include <deque>
using namespace std;

int main ()
{
deque<int> first (3); // deque with 3 zero-initialized ints
deque<int> second (5); // deque with 5 zero-initialized ints

second=first;
first=deque<int>();

cout << "Size of first: " << int (first.size()) << endl;
cout << "Size of second: " << int (second.size()) << endl;
return 0;
}
就呆在云上 2008-11-12
  • 打赏
  • 举报
回复
其实stl跟微软和大家的有什么关系呢?
msdn上面说了如果有operator=()的就有=操作,没有说有的肯定就没有,如果你觉得有必要可以字节添加一个就是了
healer_kx 2008-11-12
  • 打赏
  • 举报
回复
从来不用=,看着害怕。
liumingrong 2008-11-12
  • 打赏
  • 举报
回复
vector deque list map set都有operator=,类型要一致
Longinc 2008-11-12
  • 打赏
  • 举报
回复
看具体的API
BaihowFF 2008-11-12
  • 打赏
  • 举报
回复
因为msdn是微软的...stl是大家的...

65,210

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧