Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8963963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:28:37+00:00 2026-06-15T16:28:37+00:00

This is my method of adding 2 Duration objects together in the format (HH,MM,SS)

  • 0

This is my method of adding 2 Duration objects together in the 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;
        }
    }

In my main method i have:

  Duration dTest4 (01,25,15);
  Duration result = dTest4+dTest4;
  cout << result << endl;

Unfortunately when i run the program i get this error:

  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

I want to be able to add two times together in individual entities. Ie. The hours together, then the minutes, then the seconds. Hence the if-else to deal with when 2 sets of minutes exceed the 60min cap of an hour…

Any help would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:28:38+00:00Added an answer on June 15, 2026 at 4:28 pm

    The problem is here: cout << result << endl;
    You haven’t defined an overloaded version of std::ostream& operator<< for writing your Duration object to an ostream. Something like this should do it:

    std::ostream& operator<<(std::ostream& os, const Duration& rhs)
    { 
    os << "Hours: <" << hours_ << ">, ";  
    os << "Minutes: <" << minutes_ << ">, "; 
    os << "Seconds: <" << seconds_ << ">"; 
    return os; 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Take this method /** * @return List of group IDs the person belongs to
Can this method work? public String sayHello(){ return Hello.jsp?name= + laala; } I am
In this method I return a value of the type Double, but there is
This method right below reverses a doubly linked list with n elements. I dont
This method works as expected - it creates a JTree with a root node
This method that draws my tiles seems to be quite slow, Im not sure
This method is working totally right in matlab. but, when I compiled it in
Given this method to work on a HTML page in a webbrowser: bool semaphoreForDocCompletedEvent;
This is my javascript method in .aspx file. I want to invoke this method
With this method declaration (no overloads): void Method(double d) { // do something with

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.