Jump to content
  • Advertisement
Sign in to follow this  
ICUP

logical not operator

This topic is 3971 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

bool operator!=( const Array &right ) const
	{
		return ! ( *this == right ); // invokes Array::operator==
	}


bool Array::operator==( const Array &right ) const
{
	if ( size != right.size )
		return false; // arrays of different number of elements

	for ( int i = 0; i < size; i++ )
		if ( ptr[ i ] != right.ptr[ i ] )
			return false; // array contents are not equal

	return true; // arrays are equal
}

//// in main()
// use overloaded inequality (!=) operator
	cout << "\nEvaluating: integers1 != integers2" << endl;

	if ( integers1 != integers2 )
		cout << "integers1 and integers2 are not equal" << endl;


I'm having a hard time understanding the logical not operator in this case. So, if the array sizes are not equal, then operator== returns false. So then, when it gets back to the operator!= function, what is it returning? return !(false), which means it is returning true, or is it returning false? Or I guess another way to put it is, is the if statment reading: if( true ) or if( false )? I'm guessing if( true ) because the statement after that is printed when I run the program.

Share this post


Link to post
Share on other sites
Advertisement
If the sizes are unequal, operator== returns false. If operator== returns false, operator!= returns true. That is, operator!= returns true when the sizes are unequal.

Share this post


Link to post
Share on other sites
It's called "logical not" for a reason. :) Things are not equal when it is not the case that they are equal, and this should seem quite logical indeed.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!