Jump to content
  • Advertisement
Sign in to follow this  
barakat

WHAT IS WRONG WITH THIS ??

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

this code is generating errors ... because the compiler cant evaluate any expressions because the this pointer == NULL :'(
bool node::operator<(const node & other)
{
	assert(this);//OH MY GOD THAT FAILED 
	switch(sortMethod){
	case byID:
		return (ID<other.ID);
		break;
	case byName:
		return (strcmp(fName.c_str() , other.fName.c_str())<0 );
		break;
	case byTotals:
//canot be evaluated
		return ((cWg+fEg)<(other.cWg+other.fEg));
		break;
	default:
		assert(0);
		break;
	}

	assert(0);
	return false;
}
any help please !!!
edited by evolutional to aid code formatting [Edited by - evolutional on December 1, 2004 4:17:19 AM]

Share this post


Link to post
Share on other sites
Advertisement
Member functions are nothing more then ordinary functions with an extra parameter : the this pointer. So calling a method on a object which is NULL is perfectly OK, and won't even crash if you don't touch the objects variables (and any virtual functions).

You're method isn't the problem, it's where you call the method. The object you're calling the method on is NULL. You need to make sure that the object isn't NULL.

Share this post


Link to post
Share on other sites
Perhaps the problem is where you are calling the operator, rather then the operator itself.

If the lhs might possibly be null, I guess the assert(this) would fail - though you would expect it to fail before that.

Would be useful if you gave snippets of use.

Share this post


Link to post
Share on other sites
okay i have class list....

const list * list::sortByTotal()
{

if(isEmpty())
return 0;

list * sortedByTotalsList = new list;

node::setSortMethod(byTotals);

node * current = first ;
while(current){
sortedByTotalsList->insert(current->ID , current->fName , current->lName ,current->cWg ,current->fEg );
current = current->next;
}

return sortedByTotalsList;

}

Share this post


Link to post
Share on other sites
paulecoyote u r very right

the very silly error was in the insert function of the list itself :$

//i added the (current->next ) i was comparing current and current->next without checking current->next!!

while(current && current->next && (*(current->next) < *newNode) )
current = current->next;

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!