Problems in my tetris clone

Started by
12 comments, last by Toadhead 18 years, 11 months ago
NOO!
Not a new problem :(

I placed this above the main function in the main.cpp file:

SDL_Surface *screen;

Doesn;t that mean it;s static?
And doesn't that mean I can use this in other source files too
Than why is this wrong in another source file?:

screen = SDL_SetVideoMode(500,400,32,SDL_HWSURFACE|SDL_DOUBLEBUF);



??
Advertisement
I created a new SDL_Surface caled "loading_screen" in the loading.cpp file just to see if I get no further errors. (and used it like this: loading_screen = SDL_SetVideoMode(500,400,32,SDL_HWSURFACE|SDL_DOUBLEBUF); )

Now I get a linking error:

In function 'ZN9LoadFrame5FrameEv':
[linking error]undifined reference to 'LoadFrame::Loop()'
ID returned 1 exit status
[build error] [tetris.exe]Error 1


How am I going to fix this? :'(
(And still why doesn't my loading.cpp file recognize the screen surface while I created it above the main function?
Quote:Original post by Anonymous Poster
It is perfectly safe to have a base class pointer to a derived class instance. It is called polymorphism.


Ah crap, you are right [embarrass]. I don't know what I was thinking when I posted that. I guess I was meaning if you by chance, hackishly point one class to another, then *boom*. Brain lapse!

Quote:
SDL_Surface *screen;

Doesn;t that mean it;s static?
And doesn't that mean I can use this in other source files too
Than why is this wrong in another source file?:

screen = SDL_SetVideoMode(500,400,32,SDL_HWSURFACE|SDL_DOUBLEBUF);


Global to the scope of where it is defined in. If you want to use across many files, then you will have to make a extern declaration of it in your header file that you include in each .cpp file that want's to use it, i.e.:
extern SDL_Surface *screen; That way, the compiler knows it will be defined somewhere else, so it can be used as if it's declared in that scope of the file being compiled.

Also you do not have to do all of that. Rather than store the screen, you can always use SDL_GetVideoSurface() when you want a pointer to the screen. Makes life a lot easier [wink]. Just call : SDL_SetVideoMode(500,400,32,SDL_HWSURFACE|SDL_DOUBLEBUF); and you are all set!

Quote:
created a new SDL_Surface caled "loading_screen" in the loading.cpp file just to see if I get no further errors. (and used it like this: loading_screen = SDL_SetVideoMode(500,400,32,SDL_HWSURFACE|SDL_DOUBLEBUF); )

Now I get a linking error:

In function 'ZN9LoadFrame5FrameEv':
[linking error]undifined reference to 'LoadFrame::Loop()'
ID returned 1 exit status
[build error] [tetris.exe]Error 1


How am I going to fix this? :'(
(And still why doesn't my loading.cpp file recognize the screen surface while I created it above the main function?


Well the scren is because of the extern stuff, which I know you will fix now. The LoadFrame::Loop function is 1. not being defined or 2. The file it is defined in is not a part of the workspace. Check for both of those. Somewhere you will need to have:
void LoadFrame::Loop(){  ...}

As part of the implementations, as well as all the other classes in your child class, which leads me to beleive either #2 above is the problem, or you need to do some brushing up on C++ Classes! [wink] Good luck!
ARGHHHH
How can I make such a stupid mistake!!

I was very close, I tought I might needed to call the Loop function this way: LoadFrame::Loop() but that ofcourse didn't worked. All other functions are defined as they should be (with the LoadFrame::) so I don't know why I did this one wrong :/


Anyway thanks alot, you saved me again :D

This topic is closed to new replies.

Advertisement