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

  • Home
  • SEARCH
  • 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 6887349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:52:27+00:00 2026-05-27T05:52:27+00:00

I have classes Pile which represents a card deck, and so contains instances of

  • 0

I have classes Pile which represents a card deck, and so contains instances of class Card.
I have overloaded two operators, Pile::operator+= and Pile::operator–.

int main()
{
Pile pile1(false); //construct an empty pile/deck
Pile pile2(true);  //construct a full deck with all 52 cards
output(pile1,pile2); //just a little procedure to print both decks

pile1 += --pile2;
output(pile1,pile2);
    ...

Operator += takes another Pile as a reference and moves every card from the parameter Pile to *this.
Operator — takes the topmost card from the pile and returns a Pile containing that one card.

What g++ is giving me is a compile-time error stating

error: no match for 'operator+=' in 'pile1 += Pile::operator--()()'
note: candidate is: void Pile::operator+=(Pile&)

Below are the overloaded operators:

void Pile::operator+=(Pile &other)
{
    Node *n = other.listHead;

        //add each card from other to *this
    while((n = n->getNext()) != NULL)
    {
        this->newCardToList(other.drawCard());
    }
}

Pile Pile::operator--()
{
    Pile pile(false);
    pile.newCardToList(this->drawCard());
    return pile;
}

To me it looks like operator+= is trying to take the — as a parameter.
I tried pile1 += (–pile2); but that didn’t change anything.

The thing I want (or need to do here) is to take the topmost card from pile2
and put it to pile1. Could you suggest what is wrong here, as I haven’t been able to come up with anything?

Edit:
The += is required to modify both objects here. This is required because the person who gave us this exercise project on our course requires us to do it this way. His design has been really bad though, so I wouldn’t be surprised if this solution wasn’t even possible.

  • 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-05-27T05:52:28+00:00Added an answer on May 27, 2026 at 5:52 am

    operator += is not recognized because operator+= correct signature is:

    Pile operator+=(const Pile &other)
    

    If you want to modify other inside, you can use

    Pile& mutable_other = const_cast<Pile&>(other); 
    

    and

    Node *n = mutable_other.listHead;
    
    //add each card from other to *this
    while((n = n->getNext()) != NULL)
    {
        this->newCardToList(other.drawCard());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two classes, and want to include a static instance of one class
I have classes which are inherited from abstract Packet( this class has abstract method
I have classes like these: class MyDate { int year, month, day; } class
I have classes public class BlogPost { public int Id {get;set;} public string Body{get;set;}
I have classes Video and Audio , which extend class Popular In class, Video
I have classes which have automatic properties only like public customerName {get; set;}. They
If I have classes of Type A and B: public class A { public
I have some classes layed out like this class A { public virtual void
I have classes like this one: class SomeObject { public function __construct($param1, $param2) {
I have classes Project , Resource and File . where A Project contains LIST

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.