[SDL] Problems with pointers...
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!
Can you post some of the relevant code?
[Edited by - Amrazek on November 30, 2008 8:24:22 AM]
[Edited by - Amrazek on November 30, 2008 8:24:22 AM]
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}
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.
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?
>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!
>
>
>
>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!
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=()]
[edit: they means the destructor, copy constructor and operator=()]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement