丶Smallning 2017-03-04 04:56 采纳率: 25%
浏览 878

求教这个c++程序哪里有错

求教这个c++程序哪里有错
每次编译都会说“delete”: 不能删除不是指针的对象。
程序我是照着c++ primer打的。有些搞不明白哪里用了delete。
#include
#include
#include
#include
#include

using namespace std;

class StrBlob
{
public:
typedef vector::size_type size_type;
StrBlob();
StrBlob(initializer_list il);
size_type size() const { return data->size(); }
bool empty() const { return data->empty(); }
//添加删除
void push_back(const string &t) { data->push_back(t); }
void pop_back();
//元素访问
string& front();
string& back();
private:
shared_ptr> data;
void check(size_type i, const string &msg) const;
};

StrBlob::StrBlob() : data(make_shared>)
{
}

StrBlob::StrBlob(initializer_list il) : data(make_shared> (il))
{
}

void StrBlob::check(size_type i, const string &msg) const
{
if (i >= data->size())
{
throw out_of_range(msg);
}
}

string& StrBlob::front()
{
check(0, "front on empty StrBlob");
return data->front();
}

string& StrBlob::back()
{
check(0, "back on empty StrBlob");
return data->back();
}

void StrBlob::pop_back()
{
check(0, "no data on the vector");
data->pop_back();
}

int main()
{
StrBlob a({ "a", "b", "c" });
StrBlob b = a;
cout << b.size();
getchar();
}

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-03-04 14:58
    关注

    检查你出错的行,传入的可能不是指针

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器