2012-05-26 4 views
2

나는 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; 
} 

TRTablestd::map<State*, std::multimap<QChar, Transition>>에 대한 typedef입니다. StateQString이라는 레이블을 가지고 있으므로 .toStdString()을 호출하십시오.

나는 TuringMachine*을 beeing는 machinestd::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 및

+0

toStdString과 toAscii는 어떤 유형을 반환합니까? 오류 메시지의 줄을 아십니까? –

+0

'toStdString()'과'toAscii()'는'QString'과'QChar'의 멤버 함수입니다. 그들은'std :: string'과'char'를 각각 리턴합니다. 테이블 << std :: endl' – TeaOverflow

+3

이'operator <<'함수의 선언은 사용하려고하는 지점에서 볼 수 있습니까? (이전 파일이 같은 파일 또는 # 포함 된 헤더에 있음) – aschepler

답변

2

이있는 공간에서 당신이 operator<<를 선언 않았다

+0

내 수치심에 나는 단순히 .cpp 파일에 넣었다는 것을 인정해야만한다. 나는 여러개의 오류를 피하려고 노력하고 있었고, 헤더에 붙이고 접두어로 남겨 두었다는 사실을 모르고 있었다. '인라인 (inline) '으로 모든 것이 잘 될 것입니다. 지금처럼 :-) – TeaOverflow

0

lhs-std=c++0x을 g을 사용하여. No const.

std::ostream& operator<<(std::ostream& lhs, const TuringMachine::TRTable& rhs) 
+0

죄송합니다. 나는 오래된 버전의 기능을 붙여 넣었습니다. 내 실제 코드에는'const'가 없습니다. – TeaOverflow

0

rhsconst TuringMachine::TRTable&해야 하는가? TRTable이 typedef이므로 ADL이 적용되지 않으므로 operator<<은 실제 클래스가 정의 된 곳이므로 namespace std에서 ADL로 검색됩니다. 따라서 사용하고자 할 때 operator<<을 정의한 네임 스페이스 use이 필요할 수 있습니다.

+0

업데이트 됨. 이로 인해 오류 메시지가 변경되지 않습니다. :-( – TeaOverflow

관련 문제