Jump to content
  • Advertisement
Sign in to follow this  
Element of Power

[SDL] Problems with pointers...

This topic is 3609 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, I'm new to SDL, but I've read a few tutorials and things and I'm OK with it. My problem is, I've made a small wrapper library for it to make it easier for me to use some things, but I've encountered a problem. Some of my classes, when I try to use them cause critical errors when running my program. When I make pointers to them, then use them through the pointers, in the same way, there are no errors! Other classes cause errors if they are used through pointers, and none if they aren't. This is really confusing me, and I would like some help on the situation because I don't know when my game will get a major error because I used a pointer when I shouldn't have or vica-versa! Pleas help!

Share this post


Link to post
Share on other sites
Advertisement
int main()
{
/*My events class*/
Events e;
e.Poll();//works
Events *ep;
ep->Poll();//error
/*My surface class*/
Surface s;
s=Surface(400, 400, 32);//error
Surface *sp;
sp = new Surface(400, 400, 32);//works
}

Share this post


Link to post
Share on other sites

Events *ep;

ep->Poll();


Here, ep is a pointer, but a pointer to what? You need to initialise it, e.g.

ep = &e;


The reason your second one is failing is (probably) because your Surface class does not respect the rule of three.

Share this post


Link to post
Share on other sites
Quote:
Original post by rip-off
*** Source Snippet Removed ***

Here, ep is a pointer, but a pointer to what? You need to initialise it, e.g.

ep = &e;


The reason your second one is failing is (probably) because your Surface class does not respect the rule of three.


QFT or where you trying to do this?

int main()
{
/*My events class*/
Events e;
e.Poll();//works
Events *ep;
ep= new Events;

ep->Poll();
/*My surface class*/
Surface s;
s=Surface(400, 400, 32);
Surface *sp;
sp = new Surface(400, 400, 32);//works
}



Did you overload the = operator in your Surface class?


Share this post


Link to post
Share on other sites
>Here, ep is a pointer, but a pointer to what? You need to initialise it, e.g.
>
>
>
>ep = &e;

How could I not remember that? Thanks!

>The reason your second one is failing is (probably) because your Surface class
>does not respect the rule of three.

Never heard of the rule of three before I read that, but now I know what the problem on that one was: no copy constructor. Thanks!

Share this post


Link to post
Share on other sites
Would you like to post your Surface class? That way you can be sure they are correct.

[edit: they means the destructor, copy constructor and operator=()]

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!