编译错误 error: expected ')' before

Greatljc 2019-05-21 10:05:34
#ifndef S_T_R_B_L_O_B
#define S_T_R_B_L_O_B
#include <memory>
#include <vector>
#include <string>
#include <initializer_list>
#include <exception>

class StrBlobPtr {
public:
friend class StrBlob;
StrBlobPtr(): curr(0){};
StrBlobPtr(StrBlob &a, std::size_t d = 0): curr(d), wptr(a.data) { }; //错误的地方
error: expected ')' before '&'

std::string& deref() const;
StrBlobPtr& incur();
private:
std::size_t curr;
std::weak_ptr<std::vector<std::string> > wptr;
std::shared_ptr<std::vector<std::string> >
check(std::size_t, const std::string &) const;
};
std::shared_ptr<std::vector<std::string> >
StrBlobPtr::check(std::size_t i, const std::string &msg) const {
auto ret = wptr.lock();
if(!ret) {
throw std::runtime_error("unbound StrBlobPtr");
}
if(i >= ret->size()) {
throw std::out_of_range(msg);
}
return ret;
}

std::string& StrBlobPtr::deref() const {
auto ret = check(curr, "no");
return (*ret)[curr];
}

StrBlobPtr& StrBlobPtr::incur() {
auto ret = check(curr, "no_up");
++curr;
return *this;
}



class StrBlob {
public:
friend class StrBlobPtr;
typedef std::vector<std::string>::size_type size_type;
StrBlob() : data(std::make_shared<std::vector<std::string>>()) {};
StrBlob(std::initializer_list<std::string> i) : data(std::make_shared<std::vector<std::string>>(1)) {};
size_type size() const {return data->size();};
bool empty() const {return data->empty();};

std::string &front();
const std::string &front() const;
std::string &back();
const std::string &back() const;
/*
StrBlobPtr begin() { return StrBlobPtr(*this); }
StrBlobPtr end() {
auto ret = StrBlobPtr(*this, data->size());
return ret;
}
*/
private:
std::shared_ptr<std::vector<std::string>> data;
void check(size_type i, const std::string &msg) const;
};

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

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

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

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

const std::string &StrBlob::back() const {
check(0, "front on empty StrBlob");
return data->back();
}
#endif
#endif
std::string& deref() const;
StrBlobPtr& incur();
private:
std::size_t curr;
std::weak_ptr<std::vector<std::string> > wptr;
std::shared_ptr<std::vector<std::string> >
check(std::size_t, const std::string &) const;
};
std::shared_ptr<std::vector<std::string> >
StrBlobPtr::check(std::size_t i, const std::string &msg) const {
auto ret = wptr.lock();
if(!ret) {
throw std::runtime_error("unbound StrBlobPtr");
}
if(i >= ret->size()) {
throw std::out_of_range(msg);
}
return ret;
}

std::string& StrBlobPtr::deref() const {
auto ret = check(curr, "no");
return (*ret)[curr];
}

StrBlobPtr& StrBlobPtr::incur() {
auto ret = check(curr, "no_up");
++curr;
return *this;
}



class StrBlob {
public:
friend class StrBlobPtr;
typedef std::vector<std::string>::size_type size_type;
StrBlob() : data(std::make_shared<std::vector<std::string>>()) {};
StrBlob(std::initializer_list<std::string> i) : data(std::make_shared<std::vector<std::string>>(1)) {};
size_type size() const {return data->size();};
bool empty() const {return data->empty();};
std::string &front();
const std::string &front() const;
std::string &back();
const std::string &back() const;
/*
StrBlobPtr begin() { return StrBlobPtr(*this); }
StrBlobPtr end() {
auto ret = StrBlobPtr(*this, data->size());
return ret;
}
*/
private:
std::shared_ptr<std::vector<std::string>> data;
void check(size_type i, const std::string &msg) const;
};

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

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

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

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

const std::string &StrBlob::back() const {
check(0, "front on empty StrBlob");
return data->back();
}
#endif[/code]

请问哪里出错了

...全文
2204 回复 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2019-05-22
  • 打赏
  • 举报
回复
偶遇到类似问题都是用 “每次用/*...*/注释掉不同部分再重新编译,直到定位到具体语法出错的位置。” 的方法解决的。

65,186

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧