2016-10-12 7 views
1

私のQt C++でこのコードを使用しています。構造体を比較するための私のoperator==は、等しい場合でも常にfalseを返します。私のコードに何が問題なのですか?あなたは彼らが一致しないエラーが発生しているTEO長いリストで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)と書く必要があります。

これが失敗すると、気付かなかったように違いがあるので、等しくないものと比較します。

関連する問題