cpp小菜鸟,早起没啥事干 模仿易语言字节集.看官看看有啥错漏没有
[C++] 纯文本查看 复制代码 class bytes
{
public:
int len = 0;
unsigned char* data ;
bytes(int len) {
this->len = len;
this->data = new unsigned char[len];
//std::shared_ptr<bytes> bytesNew(new bytes(this->len + t.len));
//std::shared_ptr<byte> data(new byte[len]);
memset(data, 0, len);
}
bytes(char c) {
this->len = sizeof(c);
this->data = new unsigned char[len];
this->data[0] = c;
}
bytes(char* ch) {
this->len = sizeof(ch);
this->data =(unsigned char*) ch;
}
bytes(std::initializer_list<int> il) {
this->len = il.size();
this->data = new unsigned char[len];
int num = 0;
for (auto& i : il)
{
data[num] = i;
num++;
}
}
~bytes() {
delete[] data;
};
unsigned char& operator[](int i) const {
return data;
}
bytes operator + (bytes& t) {
bytes bytesNew(this->len + t.len);
memcpy(bytesNew.data, data, this->len);
memcpy(bytesNew.data+this->len, t.data, t.len);
this->len = this->len + t.len;
memcpy(data, bytesNew.data, bytesNew.len);
return *this;
}
bytes operator + (char* ch) {
bytes byteNew(ch);
*this = *this + byteNew;
return *this;
}
private:
};
|