作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是错字吗?
在C++入门5中。 ed页面702:
StrBlobPtr& StrBlobPtr::operator--()
{
// if curr is zero, decrementing it will yield an invalid subscript
--curr; // move the current state back one element
check(-1, "decrement past begin of StrBlobPtr");
return *this;
}
-1
进行检查将导致它始终抛出。他的意思是
check(curr, "decrement past begin of StrBlobPtr");
吗?
check
的代码段:
std::shared_ptr<std::vector<std::string>>
StrBlobPtr::check(size_type pos, const std::string &msg) const {
auto ret = wptr.lock();
if (!ret)
throw std::runtime_error("unbound StrBlobPtr");
if (pos >= ret->size())
throw std::out_of_range(msg);
return ret;
}
最佳答案
我已经检查了我的C++ Primer 6th Edition,并且以下代码出现在第567页上:
StrBlobPtr& StrBlobPtr::operator--()
{
// if curr is zero, decrementing it will yield an invalid subscript
--curr; // move the current state back one element
check(curr, "decrement past begin of StrBlobPtr");
return *this;
}
StrBlobPtr
的实现显然已经改变了很多,但这足以确认
-1
是一个错字并已在第六版中得到修复。
- Page 567: In the
StrBlobPtr::operator--()
function, the call to check should passcurr
as the first argument, not-1
.
关于c++ - C++入门5版。 StrBlobPtr减量运算符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61029018/
我是一名优秀的程序员,十分优秀!