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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T01:12:14+00:00 2026-06-05T01:12:14+00:00

I am trying to overload the assignment operator as a member function to take

  • 0

I am trying to overload the assignment operator as a member function to take a string as an argument and assigns its value to A, the current object. I posted the errors in the comments below.

Can someone tell me what I’m doing wrong? I think it has something to do with the parameters, and probably the code inside the definition.

I am not sure if I declared it correctly, but I declared it like this:

WORD operator=(const string& other);

And I defined it like this:

WORD WORD::operator=(const string& other) //<---not sure if I did the parameters Correctly
{
(*this) = other;
return (*this);
}

Here is the entire file if it helps:

#include <iostream>

using namespace std;

#pragma once

class alpha_numeric //node
{
   public:
char symbol; //data in node
alpha_numeric *next;//points to next node
};

class WORD
{
   public:
      WORD() : front(0) {length=0;}; //front of list initially set to Null
      WORD(const WORD& other);
      bool IsEmpty();
      int Length();
      void Insert(WORD bword, int position);
      WORD operator=(const string& other); 

   private:
      alpha_numeric *front; //points to the front node of a list
      int length;
};

WORD WORD::operator=(const string& other) //<---not sure if I did the parameters Correctly
{
      (*this) = other;
      return (*this);
}
  • 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-05T01:12:15+00:00Added an answer on June 5, 2026 at 1:12 am

    Ok 2 things:

    First you are missing the definition of your copy constructor, so that’s not compiling.
    Try this inside your class (only partial implementation shown):

    WORD(const WORD& other)
    : length(other.length)
    {
        // Construct me !
    }
    

    Second, your assignment operator is correct, but recursive on all control path. E.g. it calls itself indefinitely. Your probably want to assign members inside the method (again, only partial implementation shown):

    WORD WORD::operator=(const string& other)
    {
        // Only copy the length, the rest is to be filled
        this.length = other.length;
        return (*this);
    }
    

    Lastly, as others have pointed out, you have multiple definitions of the same symbols inside your executable. To fix that you will have to make sure your header is included only once (the #pragma once should take care of that) but also move all implementation details off the header file to the source file. e.g. move the definition of WORD WORD::operator=(const string& other) to the CPP file.

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

Sidebar

Related Questions

I am trying to overload operator<< as a member function. It works if simply
I'm trying to overload the comma operator with a non-friend non-member function like this:
I am trying to overload the postfix increment operator as a member function for
I'm trying to use the SelectList overload SelectList(IEnumerable, String, String, Object) In the controller:
I am trying to overload the assignment operator to do a deep copy of
I'm trying to overload the assignment operator and would like to clear a few
I'm trying to overload the dereference operator, but compiling the following code results in
I am trying to overload the * operator in order to multiply two objects
I'm trying to overload an operator in C# (don't ask why!) that applies to
I am trying to overload the << operator in my class STEntry but keep

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.