'expected constructor, desctructor or type convertor' error

hey guys, so i am making a c++ program using the sdl library in ubuntu. theres this one structure called SDL_Rect, and i tried to make an instance of it, like so:
1
2
3
4
5
6
SDL_Rect drect;

drect.x = 0;
drect.y = 0;
drect.w = 640;
drect.h = 480;


but when i tried to compile, it returned this error for each of the last 4 lines:
error: expected constructor, destructor, or type conversion before ‘.’ token

what's the matter? how to fix? thanks!
err.. something must have happened in your code paste. All I see is "r"

1
2
3
4
5
SDL_Rect myrect;
myrect.x = 1;
myrect.y = 2;
myrect.w = 3;
myrect.h = 4;
sorry- here we go

SDL_Rect drect;


drect.x = 0;
drect.y = 0;
drect.w = pscreen->w;
drect.h = pscreen->h;


thanks!
nothing wrong with that. I don't know why you're getting that error.

General troublshooting questions:
- Are you #including sdl.h?
- Do you have anything else in scope named 'drect'? maybe there's a name conflict. Try to change 'drect' to something else and see if that fixes the problem.
- Are you doing something else between SDL_Rect drect; and drect.x = 0;? Are those lines side-by-side as illustrated here, or are they in separate files or something?
changed the identifier of drect, nothing. the lines are together as well. the only thing i can think of is the way i include sdl.h- sdl is installed on my comp (the latest version), and i include it like
#include <SDL/SDL.h>
i have seen others do it like
#include "SDL.h"
but that requires you to have the sdl headers in your program directory. thanks!
Are you sure SDL/SDL.h is in one of the predefined directories that < > looks for?
The error message you gave leads me to believe that you are doing one of the following:

1) Attempting to put said code outside of any function;
2) Defining the symbol "drect" more than once.

good call, jsmith. i was trying to define the variables globally, and tried to assign values to them outside of any function as well.

so now that i have placed them all in the same function (an image processing one), that section of the code seems to compile. but once i had minimized the errors in that section, a whole slew of new ones popped up, saying i had not defined a bunch of things from sdl:

program.cpp: In function ‘void process_image(const void*, int)’:
program.cpp:190: warning: deprecated conversion from string constant to ‘char*’
/tmp/ccJ9AWck.o: In function `__static_initialization_and_destruction_0(int, int)':
program.cpp.text+0x3b1): undefined reference to `SDL_SetVideoMode'
program.cpp.text+0x3db): undefined reference to `SDL_CreateYUVOverlay'
/tmp/ccJ9AWck.o: In function `process_image(void const*, int)':
program.cpp.text+0x16ca): undefined reference to `SDL_LockYUVOverlay'
program.cpp.text+0x1700): undefined reference to `SDL_UnlockYUVOverlay'
program.cpp.text+0x1715): undefined reference to `SDL_DisplayYUVOverlay'
program.cpp.text+0x1722): undefined reference to `SDL_FreeYUVOverlay'
/tmp/ccJ9AWck.o: In function `main':
program.cpp.text+0x2410): undefined reference to `SDL_Init'
program.cpp.text+0x241c): undefined reference to `SDL_GetError'
collect2: ld returned 1 exit status

i still #include <SDL/SDL.h> at the top, so why the sudden influx of errors, if i did not get these before?

thanks, much appreciated!
You aren't linking against the SDL libraries. That's all the undefined reference errors.

The warning is _probably_ ok, but annoying anyway. Someone wrote a function that
takes a char* when the probably meant const char*. If you can't fix the function,
then const_cast<char*>( "foo" ) with a comment cursing the original programmer of
the function will suffice.


Topic archived. No new replies allowed.