问一个关于c++的问题

#include<iostream>

#include<string>

#include<vector>

#include<boost\shared_ptr.hpp>

using namespace std;

class strblodptr

{

public:

strblodptr():curr(0){}

strblodptr(weak_ptr<vector<string>>v,size_t t=0):wptr(v),curr(t){}

string&deref()const;

strblodptr&incr();

private:

size_t curr;

shared_ptr<vector<string>>check(size_t,const string&)const;

weak_ptr<vector<string>>wptr;

};

shared_ptr<vector<string>>strblodptr::check(size_t t,const string& str)const

{

auto ref=wptr.lock();

if(!ref)throw runtime_error("111111111111111111");

if(t>=ref->size())throw out_of_range(str);

return ref;

}

string&strblodptr::deref()const

{

auto p=check(curr,"dereference past end");

return (*p)[curr];

}

strblodptr&strblodptr::incr()

{

check(curr,"increment past end of strblodptr");

++curr;

return *this;

}

void main()

{

string strs[]={"My","name","is","cc"};

vector<string>v(strs,strs+4);

vector<string>*vp=new vector<string>();

*vp=v;

shared_ptr<vector<string>>sp(vp);

weak_ptr<vector<string>>wp(sp);

strblodptr ss(wp,3);

cout<<ss.deref()<<endl;

ss=ss.incr();

cout<<ss.deref()<<endl;

delete vp;

}

为什么编译器说out of range at memory?我有delete了啊,还有,要正常运行如何改?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值