나는 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()
을 호출하십시오.
TuringMachine*
을 beeing는
machine
와
std::cout << machine->table << std::endl;
전화를 다른 클래스에서
이 나에게주는
error: cannot bind 'std::ostream {aka std::basic_ostream<char>}' lvalue to 'std::basic_ostream<char>&&'
내가 잘못 뭐하는 거지? 왜 &&
일까요?
편집 : 유형 std::ostream &
을해야 ++ 4.6 및
toStdString과 toAscii는 어떤 유형을 반환합니까? 오류 메시지의 줄을 아십니까? –
'toStdString()'과'toAscii()'는'QString'과'QChar'의 멤버 함수입니다. 그들은'std :: string'과'char'를 각각 리턴합니다. 테이블 << std :: endl' – TeaOverflow
이'operator <<'함수의 선언은 사용하려고하는 지점에서 볼 수 있습니까? (이전 파일이 같은 파일 또는 # 포함 된 헤더에 있음) – aschepler