求教这个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();
}