C++ Help

4 replies [Last post]
Joined: 08/06/2010

Hi everyone,

I've been working on a project in C++, and it's suddenly failing to compile. The error is at:

ClassName& ClassName::operator += (ClassName &p){
        (*this) = (*this) + p;
        return *this;
}

(with a real class, of course)

Error message: no match found for operator = in *ClassName*this operator = operator+(ClassName&).

Any idea why this suddenly happened? The only code changed was completely unrelated.

Another Planet finally has an official release! Download chapters 1 through 3 here! Thank you for waiting so long while I kept starting over.

Joined: 07/08/2011

Do you need the parentheses around *this?

Joined: 08/06/2010

I thought operator precedence might be my problem, but they didn't fix it. Puzzled

Another Planet finally has an official release! Download chapters 1 through 3 here! Thank you for waiting so long while I kept starting over.

Joined: 12/23/2010

Personally I'd check if there's something weird in the bit that you changed the code. Missing a paranthesis or semicolon sometimes causes weird stuff to happen later/earlier on in the code. Of course my experience comes from AS3, but it probably counts with C++ too.

Joined: 09/01/2009

My guess would be this line:

(*this) = (*this) + p;

If you messed with operator+() or operator=(), or removed either, this may fail. What line is the error for?

My other guess would be to replace

ClassName& ClassName::operator += (ClassName &p)

with
ClassName& ClassName::operator+=(ClassName &p)

Spacing may be a problem, but then again, may be nothing at all.

If you can't figure it out, and want me to look at the code, I'd be more than happy to.