image = SDL_DisplayFormat( SDL_LoadBMP( "player2.bmp" ) )
Okay, here's a bit of a problem:
image = SDL_DisplayFormat(SDL_LoadBMP("player2.bmp"));
image is an SDL_Surface pointer, and player2.bmp is, well, the obvious, but that doesn't really matter.
I'm using Dev-C++ under the MingW compiler, creating an SDL based pong for starters.
From the above code, I'm recieving the error message:
39 C:\Documents and Settings\Masood.SOLTANMM.000\Desktop\main.c no match for 'operator=' in '((Paddle*)this)->Paddle::image = SDL_DisplayFormat(SDL_LoadBMP_RW(SDL_RWFromFile(((const char*)"player1.bmp"), ((const char*)"rb")), 1))'
and a note:
note C:\Program Files\Dev-Cpp\include\SDL\SDL_video.h:95 candidates are: SDL_Surface& SDL_Surface::operator=(const SDL_Surface&)
Anyone out there willing to help me out a bit, possibly explain to me why it isn't working? Or do I first need to put down my entire source code?
Thanks in advance!
It might help to split out the two function calls
bmp = SDL_LoadBMP("player2.bmp")
image = SDL_DisplayFormat(bmp);
so that you can pinpoint which call fails - or rather which part of the statement won't compile.
bmp = SDL_LoadBMP("player2.bmp")
image = SDL_DisplayFormat(bmp);
so that you can pinpoint which call fails - or rather which part of the statement won't compile.
Quote:Original post by LessBread
It might help to split out the two function calls
That and the current way you are doing it will leak memory since you do not free the surface returned from SDL_LoadBMP(). In addition, SDL_LoadBMP is a macro, so placing it inside a function call might cause it to fail. Doing it LessBread's way should work, as long as image is indeed a SDL_Surface*.
okay, posting in real-time right now...
I've just tried what you said, and I got an error only on the SDL_DisplayFormat() part.
Annnnnnnnnddddddddd...
Looked in the API, saw nothing wrong with the format... Buuutttt...
If I had not created a surface that has been set to be the video buffer (screen = SDL_SetVideoMode()) before that statement... I think I found the problem:
...blahblahblah
Okay, just fixed that by putting the entire SetVideoMode thing at the top of my source...
Still got the same error.
I feel cofused >_<
I've just tried what you said, and I got an error only on the SDL_DisplayFormat() part.
Annnnnnnnnddddddddd...
Looked in the API, saw nothing wrong with the format... Buuutttt...
If I had not created a surface that has been set to be the video buffer (screen = SDL_SetVideoMode()) before that statement... I think I found the problem:
/*This is going to be pong. Tetris comes later*/#include <stdio.h>#include <stdlib.h>#include <SDL/SDL.h>const int MAX_PLAYERS = 4;SDL_Surface *screen = NULL;class ball{ int posX; int posY; public:}class Paddle{ int posX; int posY; int keycheck[]; SDL_Surface image; public: Paddle(int playNumber); int getX() {return posX;} int getY() {return posY;} void setX(int x) {posX = x;} void setY(int y) {posY = y;} void drawANDcheck(); };Paddle::Paddle(int playNumber){ switch(playNumber) { case 1: posX = 10; posY = 250; //image = SDL_DisplayFormat(SDL_LoadBMP("player1.bmp")); SDL_Surface *bmp = SDL_LoadBMP("player1.bmp"); image = SDL_DisplayFormat(bmp); break; case 2: posX = 580; posY = 250; image = SDL_DisplayFormat(SDL_LoadBMP("player2.bmp")); break; case 3: posX = 250; posY = 580; image = SDL_DisplayFormat(SDL_LoadBMP("player3.bmp")); break; case 4: posX = 250; posY = 10; image = SDL_DisplayFormat(SDL_LoadBMP("player4.bmp")) break; }}/*void Paddle::drawANDcheck(){ SDL_Rect *dst; SDL_BlitImage();}*/int main(int argc, char *argv[]){ bool running = true; if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) { return 0; }atexit (SDL_Quit);screen = SDL_SetVideoMode(600, 600, 32, SDL_HWSURFACE|SDL_DOUBLEBUF);
...blahblahblah
Okay, just fixed that by putting the entire SetVideoMode thing at the top of my source...
Still got the same error.
I feel cofused >_<
Quote:Original post by Atash
Still got the same error.
I feel cofused >_<
SDL_Surface image;
needs to be:
SDL_Surface *image;
In your Paddle class.
Quote:Original post by LessBread
It might help to split out the two function calls
bmp = SDL_LoadBMP("player2.bmp")
image = SDL_DisplayFormat(bmp);
so that you can pinpoint which call fails - or rather which part of the statement won't compile.
In addition you might want to add error checking
bmp = SDL_LoadBMP("player2.bmp");if (NULL == bmp) // output an error message here and exit the functionimage = SDL_DisplayFormat(bmp);if (NULL == image) // output an error message// also don't forget to free the memory associated with bmp
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement