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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T14:56:16+00:00 2026-05-25T14:56:16+00:00

I have tried very very hard to solve this problem. I have always been

  • 0

I have tried very very hard to solve this problem. I have always been able to find my answer through Google, and this is the first time I have ever posted to a forum because of my due diligence. However, this has completely stumped me, and Google appears to be recommending the source code for gcc, which suggests to me that this problem is a rarity.

Here is my simplified code:

#include <sstream>
#include <string>
#include <stdio.h>
#include <stdlib.h>

using namespace std;

class DJPchar{
    public:
    //General Variables
        unsigned char *word;
        int length;

    //Initialization Functions
    DJPchar();
    DJPchar(unsigned char *w, int len);
    ~DJPchar();

    DJPchar& operator+=(const DJPchar& word2);
    };

/////////////////////////////////////////////////////////////
//Initialization Functions
/////////////////////////////////////////////////////////////
DJPchar::DJPchar(){
    word = NULL;
    length = 0;
    }

DJPchar::DJPchar(unsigned char *w, int len){
    int i;

    length = len;
    word = new unsigned char[length];
    for (i=0; i<length; i++){
        word[i] = w[i];
        }
    }

DJPchar::~DJPchar(){
    delete[] word;
    }

/////////////////////////////////////////////////////////////
//Problem Function
/////////////////////////////////////////////////////////////

DJPchar& DJPchar::operator+=(const DJPchar &word2){
    unsigned char *temp;
    int i, newlength;

    temp = this->word;
    newlength = this->length + word2.length;

    this->word = new unsigned char (newlength);

    for(i=0; i<this->length; i++){
        this->word[i] = temp[i];
        }
    for(i=this->length; i<newlength; i++){
        this->word[i] = word2.word[i-this->length];
        }

    this->length = newlength;
    delete[] temp;

    return *this;
    }

int main(){
    unsigned char a;
    unsigned char b[7];

    a = 'b';
    b[0] = 'b';
        b[1] = 'a';
        b[2] = 't';
        b[3] = '\n';
        b[4] = 200;
        b[5] = 'n';
        b[6] = '!';

    DJPchar *c_a = new DJPchar(&a, 1);
    DJPchar *c_b = new DJPchar(b, 7);

    c_a += c_b; //Error Line

    return 0;
}

I created a large list of comparison functions (I’m trying to recreate the string class for unsigned characters, if someone knows of something that exists for this, that would be swell!) and they all worked perfectly, but the error I’ve been getting for this is:

Broken.cpp:86: error: invalid operands of types ‘DJPchar*’ and ‘DJPchar*’ to binary ‘operator+’
Broken.cpp:86: error:   in evaluation of ‘operator+=(class DJPchar*, class DJPchar*)’

and I have been going nuts, looking for if I used a ‘+’ inside the function I was trying to use as the basis for the +, and then changing all kinds of pointers and whatnot, and putting it outside the class and inside the class.

Tomorrow, I may refer to rule #1 of the General rules of Operator overloading but today I’ve spent 6 hours on something that was supposed to take four minutes to verify it was working and move forward… I am a very sad panda.

  • 1 1 Answer
  • 1 View
  • 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-25T14:56:17+00:00Added an answer on May 25, 2026 at 2:56 pm

    The fix should be:

    (*c_a) += *c_b;
    

    Operators in C++ are not ‘lifted’ (like in functional languages, like e.g. Haskell; C# has the notion of lifted operator for Nullable types)

    Note @Daniel: This answer references the answer to your question (“why it should be this way”): C++ doesn’t do automatic lifted operators for pointers. I guess this is probably mainly because C++ wants to stay C-compatible with respect to pointer arithmetic instead.

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

Sidebar

Related Questions

I have tried searching over the internet about this problem but not able to
I have tried very hard but cannot find a solution on how to set
Ok, I have been having a VERY hard time figuring this out. I guess
I find it very hard to find anything official on this matter. I have
I have tried for a very long time now to figure out, why this
Have tried to find solutions for this and can't really come up with anything.
i have been trying very hard to make tinyMCE work on my page. even
I've tried very hard to have a normalized database and currently have three tables
I have tried my best to understand a very similar StackOverflow question , but
I have tried to go through the jungle (really, PayPal, why don't you weed

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.