Sign in to follow this  

All functions fail

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

Hi everyone ! I am trying to make a little engine to support my application's main frame so that I can then concentrate on the game itself. The only problem is that everything seems to fail and my debugger doesn't tell me anything more than there is a segmentation fault somewhere but I'm not sure I can trust it (I'm using Dev C++ for now since MSV is not installed yet). Could anyone look at my code and tell me what's wrong ? Game.rar
Edit by Fruny - Use HTML anchor tags to make hyperlinks.

Share this post


Link to post
Share on other sites

Point::Point() : x(0), y(0)
{
temp = new Point;
}




Oh, that's the funniest thing I've seen all day. What the heck do you think you're doing?

That's going to create another point, which will result in a point being created, which will result in another point being created, and this will keep going until you run out of stack space or memory, whichever happens first. Probably the stack.

Share this post


Link to post
Share on other sites
After looking around a bit more, I think what you're looking for is the this variable. Every object has one, it points to itself.

. . . Okay, I just looked again, I don't think that's why you wanted it. Looking at this:


Point& Point::operator+(const Point& copy) const
{

(*temp).x = x+copy.x;

(*temp).y = y+copy.y;

return (*temp);

}





I think what you want to do is get rid of that evil temp variable and have something like this:


Point & Point::operator+=(const Point& copy)
{
x += copy.x;
y += copy.y;
return *this;
}

Point Point::operator+(const Point& copy) const
{
return Point(*this)+=copy;
}



Share this post


Link to post
Share on other sites

This topic is 4687 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this