一种打印多地图地图的方法
A way to print of map of multimaps?
我试图超载operator<<
,这让我发疯:
std::ostream& operator<<(std::ostream & lhs, TuringMachine::TRTable& rhs){
for(auto& statePtr : rhs){
lhs << statePtr.first->getLabel().toStdString();
for(auto& charPtr: statePtr.second){
//lhs << 't';
lhs << charPtr.first.toAscii() ;
//lhs << 'b ';
lhs << charPtr.second.getState().getLabel().toStdString() << std::endl;
}
}
return lhs;
}
TRTable
是std::map<State*, std::multimap<QChar, Transition>>
的typedef
。 State
的标签是QString
因此呼吁.toStdString()
.
在另一堂课上,我称std::cout << machine->table << std::endl;
与machine
蜂TuringMachine*
,这给了我
error: cannot bind 'std::ostream {aka std::basic_ostream<char>}' lvalue to 'std::basic_ostream<char>&&'
我做错了什么?为什么&&
?
编辑:使用g ++ 4.6和-std=c++0x
您在哪个命名空间中声明了operator<<
?由于TRTable
是一个 typedef ADL 不适用,因此 ADL 仅在namespace std
中搜索operator<<
,因为这是定义实际类的地方。因此,当您想要使用它时,您可能必须use
在其中定义operator<<
的命名空间。
lhs
应该有类型 std::ostream &
。没有const
.
rhs
应该const TuringMachine::TRTable&
:
std::ostream& operator<<(std::ostream& lhs, const TuringMachine::TRTable& rhs)
相关文章:
- 在 c++ 中,有一种方法可以创建一个包含地图作为值的树状地图?
- C++将所有元素从矢量复制到地图/unordered_map的最佳方法
- 如何调用返回双精度或字符串并将其保存在地图上但作为对象的类的方法
- 无法理解使用这张地图背后的证明<>方法
- 获取地图值作为向量的最佳方法是什么
- 将信息从 2D 矢量传输到地图的最快方法是什么
- 在游戏地图上选择100种情况的最佳方法(MFC,CPoint)
- C - 搜索地图中具有相同值的所有键的最快方法是什么
- 删除多地图中重复项的有效方法
- 使用 SDL2 渲染平铺地图的最快方法
- 按值在地图中查找 - 方法在速度方面的偏好
- 清理地图中所有共享指针的正确方法是什么
- 将自定义类型作为地图的可能键的可能方法有哪些
- 获取按地图值排序的映射键向量的最快方法
- 如何将地图作为参数传递并在此方法中添加
- 对基于地图C++集合重新排序的有效方法
- 一种打印多地图地图的方法
- C++标准::地图比较方法
- 插入标准::地图的最佳方法
- 清除地图和删除内容的最简洁的方法是什么?