これは、2 つの Duration オブジェクトを一緒に format に追加する私の方法です(HH,MM,SS)。
    inline ostream& operator<<(ostream& ostr, const Duration& d){
      return ostr << d.getHours() << ':' << d.getMinutes() << ':' << d.getSeconds();
    }
    Duration operator+ (const Duration& x, const Duration& y){
        if ( (x.getMinutes() + y.getMinutes() >= 60) && (x.getSeconds() + y.getSeconds() >= 60) ){
           Duration z( (x.getHours() + y.getHours() + 1), (x.getMinutes() + y.getMinutes() + 1 - 60), (x.getSeconds() + y.getSeconds() - 60) );
           return z;
        }
        else if (x.getSeconds() + y.getSeconds() >= 60){
           Duration z( (x.getHours() + y.getHours()), (x.getMinutes() + y.getMinutes() + 1), (x.getSeconds() + y.getSeconds() - 60) );
           return z;
        }
        else if (x.getMinutes() + y.getMinutes() >= 60){
           Duration z( (x.getHours() + y.getHours() + 1), (x.getMinutes() + y.getMinutes() - 60), (x.getSeconds() + y.getSeconds()) );
           return z;
        }
        else{
            Duration z( (x.getHours() + y.getHours()), (x.getMinutes() + y.getMinutes()), (x.getSeconds() + y.getSeconds()) );
            return z;
        }
    }
私の主な方法では:
  Duration dTest4 (01,25,15);
  Duration result = dTest4+dTest4;
  cout << result << endl;
残念ながら、プログラムを実行すると、次のエラーが発生します。
  error LNK2019: unresolved external symbol "class std::basic_ostream<char,struct std::char_traits<char> > & __cdecl operator<<(class std::basic_ostream<char,struct std::char_traits<char> > &,class Duration const &)" (??6@YAAAV?$basic_ostream@DU?$char_traits@D@std@@@std@@AAV01@ABVDuration@@@Z) referenced in function _wmain 1>C:\Users\...exe : fatal error LNK1120: 1 unresolved externals
個々のエンティティで 2 回を一緒に追加できるようにしたい。すなわち。時間、次に分、そして秒。したがって、if-else2 セットの分が 1 時間の上限である 60 分を超えた場合に対処する必要があります...
どんな助けでも大歓迎です。