Jump to content
  • Advertisement
Sign in to follow this  
Hammonjj

Members Calling Members

This topic is 3984 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I get an error when I compile my code and here is the "errored" portion along with the relevent support code. The error I get is: error: no match for 'operator==' in 'this == anotherBigNum' What I am gathering from this is that the compiler doesn't realize that == was defined right above it. What can I do to fix this? Thanks
    bool BigNum::operator==(const BigNum &anotherBigNum)
    {
		if(used != anotherBigNum.used)
		{
			return false;
		}
		
		for(int i = 0; i < used; i++)
		{
			if(digits != anotherBigNum.digits)
			{
				return false;
			}
		}
		return true;
    }
    
    
    bool BigNum::operator!=(const BigNum &anotherBigNum)
    {
		if(!(this == anotherBigNum))
		{
			return true;
		}
		return false;
	}

Share this post


Link to post
Share on other sites
Advertisement
if(!(*this == anotherBigNum))

You need to dereference (*) the this pointer.

Otherwise, when you use this pointer, you are comparing a pointer-to-BigNum to a BigNum, rather than a BigNum to a BigNum, which your == method defines.

HTH

Share this post


Link to post
Share on other sites
A simpler way:


bool BigNum::operator!=(const BigNum &anotherBigNum)
{
return !(*this == anotherBigNum);
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!