求高手来解答!!!!

yangommo 2011-12-07 03:16:32
Please consider the code below:

class Buffer
{
public:
Buffer() : size(0), data(0) {}
Buffer(int s, void* d)
{
if (s <= 0) throw std::invalid_argument();
data = d;
size = s;
}
~Buffer() { delete data; }
void** operator&() { return &data; }

private:
Buffer& operator=(const Buffer&);

int size;
void* data;
}

Does this code has any restrictions, which do not allow to use objects of this class into the std containers (std:vector<Buffer>)? Is yes, please describe them.
...全文
91 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangommo 2011-12-07
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 ouyh12345 的回复:]
需要拷贝构造函数
[/Quote]
在帮忙看这个问题,高人!

Please look at the code:

template <typename T> void Func2(std::auto_ptr<T> v1, std::auto_ptr<T> v2, std::auto_ptr<T> v3)
{
<…>
}

template <typename T> bool Func1()
{
try
{
std::auto_ptr<T> p(new T);
Func2(p, std::auto_ptr<T> (new T), std::auto_ptr<T>(new T));
p->SomeMethod();
return true;
}
catch(const std::bad_alloc&)
{
return false;
}
}

Answer the questions:

Do you see any problems in this code?
Is this code an exception safe?
If you see any problems please mark all of them (by using the following style: line of code – description of the problem; for example: “printf(s) – uninitialized variable s”).

turing-complete 2011-12-07
  • 打赏
  • 举报
回复
yeah, it really has !

description over.
ouyh12345 2011-12-07
  • 打赏
  • 举报
回复
需要拷贝构造函数

64,662

社区成员

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

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