2016-10-12 18 views
1

Qt C++의 응용 프로그램에이 코드가 있습니다. 구조체를 비교하기위한 내 operator==은 동등하더라도 항상 false를 반환합니다. 내 코드에 무슨 문제가 있습니까? 당신은 그들이 동일하지 않은 오류가있는 테오 긴 목록에서std :: tie를 사용하여 구조체 비교

struct pSettings 
{ 
    int speciality; 
    bool autoCompleteByWord; 
    bool showChronicConditions; 
    bool showNavArrows; 
    bool smallScreenMode; 
    bool simpleExamination; 
    bool alwaysSave; 
    bool inLinePatientList; 
    double newVisitPrice; 
    double followVisitprice1; 
    double followVisitprice2; 
    double followVisitprice3; 
    double followVisitprice4; 
    int autosaveinterval; 
    bool autoSave ; 
    bool minimizeToTray; 
    int selectedTheme; 
    QString textColor; 
    QString topBGColor; 
    QString bottomBGColor; 
    QString altWinColor; 
    QString buttonColor; 
    QString altButtonColor; 
    QString textBGColor; 
    QString borderColor1; 
    QString borderColor2; 
    QString altButtonColorHover; 
    QString buttonColorHover; 
    QString buttonColorDisabled; 
    QString buttonBorderColorHover; 
    QString comboBGcolor; 
    QString buttonTextColor; 
    QString comboTextColor; 
    double lOffSet,tOffSet; 

    QString defaultFont; 
    double defaultFontSize; 
    bool defaultFontBold; 

    QString textboxFont; 
    double textboxFontSize; 
    bool textboxFontBold; 

    int maxFollowUps; 
    bool autoClosePrintDlg; 
    int maxFollowUpsPerProblem; 
    bool autoSetnewAfterMaxPerProblemIsReached; 
    int checkoutDate; 
    int checkoutTime; 
    bool enableVisualEffects; 

    bool operator==(const pSettings& psettings) const 
    { 
     return std::tie(
        speciality, 
        autoCompleteByWord, 
        showChronicConditions, 
        showNavArrows, 
        smallScreenMode, 
        simpleExamination, 
        alwaysSave, 
        inLinePatientList, 
        newVisitPrice, 
        followVisitprice1, 
        followVisitprice2, 
        followVisitprice3, 
        followVisitprice4, 
        autosaveinterval, 
        autoSave , 
        minimizeToTray, 
        selectedTheme, 
        textColor, 
        topBGColor, 
        bottomBGColor, 
        altWinColor, 
        buttonColor, 
        altButtonColor, 
        textBGColor, 
        borderColor1, 
        borderColor2, 
        altButtonColorHover, 
        buttonColorHover, 
        buttonColorDisabled, 
        buttonBorderColorHover, 
        comboBGcolor, 
        buttonTextColor, 
        comboTextColor, 
        lOffSet, 
        tOffSet, 
        defaultFont, 
        defaultFontSize, 
        defaultFontBold, 
        textboxFont, 
        textboxFontSize, 
        textboxFontBold, 
        maxFollowUps, 
        autoClosePrintDlg, 
        maxFollowUpsPerProblem, 
        autoSetnewAfterMaxPerProblemIsReached, 
        checkoutDate, 
        checkoutTime, 
        enableVisualEffects) == 
       std::tie(psettings.speciality, 
         psettings.autoCompleteByWord, 
         psettings.showChronicConditions, 
         psettings.showNavArrows, 
         psettings.smallScreenMode, 
         psettings.simpleExamination, 
         psettings.alwaysSave, 
         psettings.inLinePatientList, 
         psettings.newVisitPrice, 
         psettings.followVisitprice1, 
         psettings.followVisitprice2, 
         psettings.followVisitprice3, 
         psettings.followVisitprice4, 
         psettings.autosaveinterval, 
         psettings.autoSave , 
         psettings.minimizeToTray, 
         psettings.selectedTheme, 
         psettings.textColor, 
         psettings.topBGColor, 
         psettings.bottomBGColor, 
         psettings.altWinColor, 
         psettings.buttonColor, 
         psettings.altButtonColor, 
         psettings.textBGColor, 
         psettings.borderColor1, 
         psettings.borderColor2, 
         psettings.altButtonColorHover, 
         psettings.buttonColorHover, 
         psettings.buttonColorDisabled, 
         psettings.buttonBorderColorHover, 
         psettings.comboBGcolor, 
         psettings.buttonTextColor, 
         psettings.comboTextColor, 
         psettings.lOffSet, 
         psettings.tOffSet, 
         psettings.defaultFont, 
         psettings.defaultFontSize, 
         psettings.defaultFontBold, 
         psettings.textboxFont, 
         psettings.textboxFontSize, 
         psettings.textboxFontBold, 
         psettings.maxFollowUps, 
         psettings.autoClosePrintDlg, 
         psettings.maxFollowUpsPerProblem, 
         psettings.autoSetnewAfterMaxPerProblemIsReached, 
         psettings.checkoutDate, 
         psettings.checkoutTime, 
         psettings.enableVisualEffects); 
    } 

}; 
+1

코드를 관련 항목에 맞게 좁힐 수 있습니까? –

+1

@dasblinkenlight'std :: tie'는 괜찮습니다. 'tuple'을 사용하면 모든 데이터가 복사됩니다. – juanchopanza

+0

std :: tie는 내가 사용하기 원하는 이유가 더 간단합니다 –

답변

4

어딘가에 : 여기

문제가있는 코드이다. DRY (자신을 반복하지 마십시오)를 위반했습니다. C++ 14

:

auto mytie() const { 
    return std::tie(/* ... fields */); 
} 

나서 그 사용 == 물품.

C++ 11에서는 적절한 상태를 유지하기 위해 로컬 (상태 비 저장) 람다로 mytie(blah const& self)을 써야합니다.

이것이 실패하면, 사용자가 알지 못하는 방식으로 다르기 때문에 비 동일도를 비교합니다.