void print(){
auto ofunc = operator<<[=](ostream& cout,const pair& p) ->ostream& {
cout<<*(p.pval);
return cout;
};
// 就是这里有错, 这里的问题, 我不知道 怎么 搞了 , 想给 局部类 重载 <<
class pair {
public:
friend ostream& operator<<(ostream& cout,const pair& p);
int index;
const Vtyp* pval;
pair() : index(-1),pval(nullptr){}
pair(int i,const Vtyp* pv) : index(i),pval(pv){}
const bool operator<(const pair& p) const {
return this->index< p.index;
}
};
// 这里是类的 定义 , 大姐不用看了
}
类中友元函数声明跟上面的lambda表达式没关系,而且lambda表达式形参列表用的是引用,但定义部分使用了类成员,所以需要在此lambda表达式定义体作用域之前声明并定义pair类。