C++ 箭头运算符和boost多数组迭代器
boost多数组迭代器中是否缺少箭头运算符?我期望这会起作用,这是错的吗C++ 箭头运算符和boost多数组迭代器,c++,boost,boost-multi-array,C++,Boost,Boost Multi Array,boost多数组迭代器中是否缺少箭头运算符?我期望这会起作用,这是错的吗 #include <vector> #include <boost/multi_array.hpp> struct foo { int n; }; int main() { { std::vector<foo> a; auto it = a.begin(); int test = it->n; // this do
#include <vector>
#include <boost/multi_array.hpp>
struct foo {
int n;
};
int main()
{
{
std::vector<foo> a;
auto it = a.begin();
int test = it->n; // this does compile
}
{
boost::multi_array<foo, 1> a;
auto it = a.begin();
int test = it->n; // this does not compile
}
return 0;
}
#包括
#包括
结构foo{
int n;
};
int main()
{
{
std::载体a;
自动it=a.begin();
int test=it->n;//这会编译
}
{
boost::多_阵列a;
自动it=a.begin();
int test=it->n;//这不会编译
}
返回0;
}
似乎是个bug<代码>数组迭代器::运算符->返回一个:
// reference here is foo&
operator_arrow_proxy<reference> operator->() const;
//这里的引用是foo&
运算符\箭头\代理运算符->()常量;
其中:
template <class T>
struct operator_arrow_proxy
{
operator_arrow_proxy(T const& px) : value_(px) {}
T* operator->() const { return &value_; }
// This function is needed for MWCW and BCC, which won't call operator->
// again automatically per 13.3.1.2 para 8
operator T*() const { return &value_; }
mutable T value_;
};
模板
结构运算符\u箭头\u代理
{
操作符箭头代理(T const&px):值(px){
T*运算符->()常量{return&value}
//MWCW和BCC需要此功能,不会调用运算符->
//再次根据13.3.1.2第8段自动进行
运算符T*()常量{return&value}
可变T值;
};
但是
T*
这里将是foo&*
,您不能使用指向引用的指针。此外,您不能有可变的
引用成员。因此,对于这个用例,整个类模板都被破坏了 发生了什么类型的编译错误?'->':指向boost\multi_array\iterator.hppshucks中引用的指针是非法的
。“这容易解决吗?”我想是的。