Server Help

Non-Subspace Related Coding - can't compile c++ code

hellzlaker - Fri May 09, 2008 7:41 pm
Post subject: can't compile c++ code
I was learning SDL tutorial but it did not compile my code neither on DEVC++ or VC++

here is code

Code: Show/Hide
#include <sdl.h>
#include <string.h>

const int screen_w = 500;
const int screen_h = 500;
const int screen_bpp = 32;

SDL_Surface *message = NULL;
SDL_Surface *background = NULL;
SDL_Surface *screen = NULL;

SDL_Surface *load_image(std::string fileName)
{
   SDL_Surface* loadedImage = NULL;
   SDL_Surface* optimizedImage = NULL;

   loadedImage = SDL_LoadBMP(fileName.c_str());

   if (loadedImage!=NULL)
   {
      optimizedImage = SDL_DisplayFormat(loadedImage);

      SDL_FreeSurface(loadedImage);
   }

   return optimizedImage;
}

void apply_surface(int x,int y, SDL_Surface* source, SDL_Surface destination)
{
   SDL_Rect offset;

   offset.x = x;
   offset.y = y;

   SDL_BlitSurface(source,NULL,destination,&offset);
}

int main(int argc, char* args[])
{

   if (SDL_Init(SDL_INIT_EVERYTHING)== -1))
   {
      return 1;
   }

   screen = SDL_SetVideoMode(screen_w,screen_h,screen_bpp,SDL_SWSURFACE);

   if (screen == NULL)
   {
      return 1;
   }

   SDL_WM_SetCaption("A3 Pokemon 2",NULL);

   message = load_image("logo.bmp");
   background = load_image("bg.bmp");

   apply_surface(0,0,background,screen);
   apply_surface(102,175,message,screen);

   if (SDL_Flip == -1)
   {
      return 1;
   }

   SDL_Delay(3000);

   SDL_FreeSurface(backround);
   SDL_FreeSurface(message);


   SDL_Quit();

   return 0;
}



here are the errors

Code: Show/Hide
1>------ Build started: Project: A3 Pokemon 2, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>c:\documents and settings\owner\desktop\programing\c++\a3 pokemon 2 vc version\a3 pokemon 2\a3 pokemon 2\main.cpp(12) : error C2653: 'std' : is not a class or namespace name
1>c:\documents and settings\owner\desktop\programing\c++\a3 pokemon 2 vc version\a3 pokemon 2\a3 pokemon 2\main.cpp(12) : error C2065: 'string' : undeclared identifier
1>c:\documents and settings\owner\desktop\programing\c++\a3 pokemon 2 vc version\a3 pokemon 2\a3 pokemon 2\main.cpp(12) : error C2146: syntax error : missing ')' before identifier 'fileName'
1>c:\documents and settings\owner\desktop\programing\c++\a3 pokemon 2 vc version\a3 pokemon 2\a3 pokemon 2\main.cpp(12) : error C2059: syntax error : ')'
1>c:\documents and settings\owner\desktop\programing\c++\a3 pokemon 2 vc version\a3 pokemon 2\a3 pokemon 2\main.cpp(13) : error C2143: syntax error : missing ';' before '{'
1>c:\documents and settings\owner\desktop\programing\c++\a3 pokemon 2 vc version\a3 pokemon 2\a3 pokemon 2\main.cpp(13) : error C2447: '{' : missing function header (old-style formal list?)
1>c:\documents and settings\owner\desktop\programing\c++\a3 pokemon 2 vc version\a3 pokemon 2\a3 pokemon 2\main.cpp(36) : error C2664: 'SDL_UpperBlit' : cannot convert parameter 3 from 'SDL_Surface' to 'SDL_Surface *'
1>        No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1>c:\documents and settings\owner\desktop\programing\c++\a3 pokemon 2 vc version\a3 pokemon 2\a3 pokemon 2\main.cpp(42) : error C2059: syntax error : ')'
1>c:\documents and settings\owner\desktop\programing\c++\a3 pokemon 2 vc version\a3 pokemon 2\a3 pokemon 2\main.cpp(56) : error C2064: term does not evaluate to a function taking 1 arguments
1>c:\documents and settings\owner\desktop\programing\c++\a3 pokemon 2 vc version\a3 pokemon 2\a3 pokemon 2\main.cpp(57) : error C2064: term does not evaluate to a function taking 1 arguments
1>c:\documents and settings\owner\desktop\programing\c++\a3 pokemon 2 vc version\a3 pokemon 2\a3 pokemon 2\main.cpp(59) : error C2664: 'apply_surface' : cannot convert parameter 4 from 'SDL_Surface *' to 'SDL_Surface'
1>        No constructor could take the source type, or constructor overload resolution was ambiguous
1>c:\documents and settings\owner\desktop\programing\c++\a3 pokemon 2 vc version\a3 pokemon 2\a3 pokemon 2\main.cpp(60) : error C2664: 'apply_surface' : cannot convert parameter 4 from 'SDL_Surface *' to 'SDL_Surface'
1>        No constructor could take the source type, or constructor overload resolution was ambiguous
1>c:\documents and settings\owner\desktop\programing\c++\a3 pokemon 2 vc version\a3 pokemon 2\a3 pokemon 2\main.cpp(62) : error C2446: '==' : no conversion from 'int' to 'int (__cdecl *)(SDL_Surface *)'
1>        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\owner\desktop\programing\c++\a3 pokemon 2 vc version\a3 pokemon 2\a3 pokemon 2\main.cpp(62) : error C2040: '==' : 'int (__cdecl *)(SDL_Surface *)' differs in levels of indirection from 'int'
1>c:\documents and settings\owner\desktop\programing\c++\a3 pokemon 2 vc version\a3 pokemon 2\a3 pokemon 2\main.cpp(69) : error C2065: 'backround' : undeclared identifier
1>Build log was saved at "file://c:\Documents and Settings\Owner\Desktop\Programing\c++\A3 Pokemon 2 VC version\A3 Pokemon 2\A3 Pokemon 2\Debug\BuildLog.htm"
1>A3 Pokemon 2 - 15 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Samapico - Fri May 09, 2008 8:23 pm
Post subject:
Just check the damn errors... the first one:

std is not a class or namespace... once you get that everything fucks up. I have no idea why there is 'std::string' in there, especially since <string.h> is included, just use 'string'

(old-style formal list?) might refer to the use of std::... dunno.

and... backround instead of background...
(69) : error C2065: 'backround' : undeclared identifier

how is that not obvious?

Read the errors sloooooowly next time... They are there for a reason. Even if you don't understand anything (which often happens), you get the line number. Go see that line, and check what is wrong.
hellzlaker - Fri May 09, 2008 8:57 pm
Post subject:
EDIT i got it to 1 error but i have no idea how to fix it
Code: Show/Hide
1>------ Build started: Project: A3 Pokemon 2, Configuration: Debug Win32 ------
1>Compiling...
1>main.cpp
1>c:\documents and settings\owner\desktop\programing\c++\a3 pokemon 2 vc version\a3 pokemon 2\a3 pokemon 2\main.cpp(62) : error C2446: '==' : no conversion from 'int' to 'int (__cdecl *)(SDL_Surface *)'
1>        Conversion from integral type to pointer type requires reinterpret_cast, C-style cast or function-style cast
1>c:\documents and settings\owner\desktop\programing\c++\a3 pokemon 2 vc version\a3 pokemon 2\a3 pokemon 2\main.cpp(62) : error C2040: '==' : 'int (__cdecl *)(SDL_Surface *)' differs in levels of indirection from 'int'
1>Build log was saved at "file://c:\Documents and Settings\Owner\Desktop\Programing\c++\A3 Pokemon 2 VC version\A3 Pokemon 2\A3 Pokemon 2\Debug\BuildLog.htm"
1>A3 Pokemon 2 - 2 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

Samapico - Sat May 10, 2008 12:19 am
Post subject:
future reminder: you should tell us which line is line 62... cause we have to copy-paste it in notepad, and then scroll to find the line... while you could save us that time since you have the line numbers written in the IDE.


From what I understand, SDL_Flip is some kind of pointer (could you get the declaration of SDL_Flip?; go in the sdl.h file you should find it)
So it tries to compare that thing, with -1. To do that, it must convert SDL_Flip to the same type as -1, which is an int. And apparently, it cannot.
So... since I have no idea what SDL_Flip is, I can't help you more :/
hellzlaker - Sat May 10, 2008 12:35 pm
Post subject:
This is what i found when i searched for delcaration and definition,
Code: Show/Hide
extern DECLSPEC int SDLCALL SDL_Flip(SDL_Surface *screen);


and its declared as an int :\


EDIT: the guy that made that tutorial made over 20 errors, i got it all fixed up turns out flip was a function..
k0zy - Sat May 10, 2008 1:49 pm
Post subject:
SDL_Flip is a function and not an integer.
Samapico - Sat May 10, 2008 3:58 pm
Post subject:
What kind of function? Does it return an int?
Then it should be
if (SDL_Flip() == -1)
hellzlaker - Sat May 10, 2008 4:31 pm
Post subject:
yes it does but it reqiures 1 parameter i fixed it up, SDL_Flip(screen)==-1
All times are -5 GMT
View topic
Powered by phpBB 2.0 .0.11 © 2001 phpBB Group