一个英文笔试问题
- C/C++ code
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.请各位赐教一二 这个类有什么限制啊
[解决办法]
~Buffer() { delete data; }
万一data是一个数组呢? 万一data不是new出来的呢?
[解决办法]
vector<Buffer>
Buffer没提供拷贝构造函数,赋值函数为private,则此数组不支持push_back和assign操作
Buffer没提供==函数,不支持std::find
[解决办法]
void** operator&() { return &data; }
这个data可能是0,&0好像是不行的吧