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 9289623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T20:13:34+00:00 2026-06-18T20:13:34+00:00

I have overloaded these operators to help me traverse a doubly linked list, but

  • 0

I have overloaded these operators to help me traverse a doubly linked list, but have run into a small bug, and being still new to c++ I am stuck. I never accounted for it the “amount” entered in would be a negative number. So I think I need to put a check in each operator for a negative number, because it will dramatically change the way I traverse the list, example, if im pointing at node 5 and I +(-3) I would want it to move backwards three nodes, the same with the -, 5 – (-3) would be go ahead three nodes. the logic seems easy, but the syntax is confusing. Here are the operators overloaded:

template <typename T>
typename doublyLinkedList<T>::iterator doublyLinkedList<T>::iterator::operator+(const int amount) const {
    doublyLinkedList<T>::iterator tempClone(*this);
    tempClone.pastBoundary=false;
    T i;

    for(i=0; i < amount; i++)
    {   
       if(tempClone.current->forward == NULL)
       {
          tempClone.pastBoundary =true;
       }else
       {
          ++tempClone;
       }
    }

    if(tempClone.pastBoundary == true)
    {
       return *this;
    }else
    {
        return tempClone;   
    }
}
template <typename T>
typename doublyLinkedList<T>::iterator doublyLinkedList<T>::iterator::operator-(const int amount) const {
    doublyLinkedList<T>::iterator tempClone(*this);
    tempClone.pastBoundary=false;
    T i;

    for(i=0; i < amount; i++)

       {    
        if(tempClone.current->backward == NULL)
       {
          tempClone.pastBoundary =true;
       }else
       {
          --tempClone;
       }
    }


    if(tempClone.pastBoundary == true)
    {
       return *this;
    }else
    {
        return tempClone;   
    }
}
  • 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-18T20:13:35+00:00Added an answer on June 18, 2026 at 8:13 pm

    if(amount = (-amount)) – unless amount is 0, this is always true.

    And it needs to go before the for-loop. In fact, I would probably do:

    if (amount < 0) return this->operator-(-amount); 
    

    and vise versa for the other operator.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm in the process of creating a double-linked list, and have overloaded the operator=
So I have these two overloaded operators for my Vector class, dot and cross
I have 2 classes with overloaded operators in a namespace called Dinero, these are
If I have have some overloaded ostream operators, defined for library local objects, is
I am currently creating a utility class that will have overloaded operators in it.
I need help with creating Operator-Overloaded functions please. I tried 2 but I am
I have a class called Message which overloads these operators: public static bool operator
Are there exceptions for types which can't have thier assignment operator overloaded? Specifically, I'm
I have overloaded the + operator like this class sample { private : int
I have an overloaded action in my Controller: public ActionResult AssignList(int id) { ...

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.