cannot convert 'SDL_DisplayMode' to 'SDL_DisplayMode*

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

cannot convert 'SDL_DisplayMode' to 'SDL_DisplayMode*

speartip
Hi,

I am struggling with some pretty straight forward c/c++ & SDL code. But I am not feeling the straightforwardness of it though. I don't know if its a c++ issue or SDL. I try to call SDL fx code from an external .cpp/.h. I am trying to make these reusable and to release main from clutter. Everything runs smoothly until the second block:








Code:

int horizontal = 0;
int vertical = 0;
SDL_DisplayMode dm;
cout<<"Gobot call:";
gobot(horizontal, vertical,&dm);









Code:

#ifndef GOBOT_CPP_
#define GOBOT_CPP_

#include "SDL.h"
#include "gobot.h"


int gobot( int &horizontal, int &vertical, &dm )
   {
      //SDL_GetDesktopDisplayMode(0, &dm);
      horizontal = dm->w;
      vertical = dm->h;
      return 0;
   }
   //cout<<"Resolution: x = "< #endif /* GOBOT_CPP_ */









Code:

#ifndef GOBOT_H_
#define GOBOT_H_
#include"SDL.h"

int SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode * dm);
int gobot(int horizontal, int vertical, SDL_DisplayMode * dm);

#endif /* GOBOT_H_ */


error:
In function 'int SDL_main(int, char**)':
..\src\SpearTip.cpp:50:35: error: cannot convert 'SDL_DisplayMode' to 'SDL_DisplayMode*' for argument '3' to 'int gobot(int, int, SDL_DisplayMode*)'
gobot(horizontal, vertical, dm);


Thanks

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|

Re: cannot convert 'SDL_DisplayMode' to 'SDL_DisplayMode*

Brian Puthuff
Your .H function declaration (prototype) for gobot and your .CPP function need to have the same arguments and return types.
If your goal is to pass horizontal and vertical and dm into the function, and then store the display mode's width and height data into horizontal and vertical respectively, then you need to have the function take in pointers to horizontal and vertical. Then in your function definition, deference your pointers and store the values obtained by dm. Hopefully that makes sense.


Code:

int horizontal = 0;
int vertical = 0;
SDL_DisplayMode dm;
cout<<"Gobot call:";
gobot(&horizontal, &vertical, &dm);


In your .CPP Definition:

int gobot( int* horizontal, int* vertical, SDL_DisplayMode* dm )
   {
      //SDL_GetDesktopDisplayMode(0, &dm);
      *horizontal = dm->w;
      *vertical = dm->h;
      return 0;
   }

In your .H Declaration
int gobot( int* horizontal, int* vertical, SDL_DisplayMode* dm );

On Tue, Feb 7, 2017 at 5:20 PM, speartip <[hidden email]> wrote:
Hi,

I am struggling with some pretty straight forward c/c++ & SDL code. But I am not feeling the straightforwardness of it though. I don't know if its a c++ issue or SDL. I try to call SDL fx code from an external .cpp/.h. I am trying to make these reusable and to release main from clutter. Everything runs smoothly until the second block:




Code:


int horizontal = 0;
int vertical = 0;
SDL_DisplayMode dm;
cout<<"Gobot call:";
gobot(horizontal, vertical,&dm);







Code:


#ifndef GOBOT_CPP_
#define GOBOT_CPP_

#include "SDL.h"
#include "gobot.h"


int gobot( int &horizontal, int &vertical, &dm )
   {
      //SDL_GetDesktopDisplayMode(0, &dm);
      horizontal = dm->w;
      vertical = dm->h;
      return 0;
   }
   //cout<<"Resolution: x = "<


Code:


#ifndef GOBOT_H_
#define GOBOT_H_
#include"SDL.h"

int SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode * dm);
int gobot(int horizontal, int vertical, SDL_DisplayMode * dm);

#endif /* GOBOT_H_ */




error:
In function 'int SDL_main(int, char**)':
..\src\SpearTip.cpp:50:35: error: cannot convert 'SDL_DisplayMode' to 'SDL_DisplayMode*' for argument '3' to 'int gobot(int, int, SDL_DisplayMode*)'
gobot(horizontal, vertical, dm);


Thanks

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|

Re: cannot convert 'SDL_DisplayMode' to 'SDL_DisplayMode*

speartip
I made the exact changes; still getting errors:

.\src\gobot.cpp:15:45: error: 'dm' has not been declared
int gobot( int * horizontal, int* vertical, dm )
                                             ^
..\src\gobot.cpp: In function 'int gobot(int*, int*, int)':
..\src\gobot.cpp:18:18: error: 'dm' was not declared in this scope
   * horizontal = dm->w;


--
  Gray Family



On Tue, Feb 7, 2017, at 09:11 PM, Brian Puthuff wrote:
Your .H function declaration (prototype) for gobot and your .CPP function need to have the same arguments and return types.
If your goal is to pass horizontal and vertical and dm into the function, and then store the display mode's width and height data into horizontal and vertical respectively, then you need to have the function take in pointers to horizontal and vertical. Then in your function definition, deference your pointers and store the values obtained by dm. Hopefully that makes sense.


Code:


int horizontal = 0;
int vertical = 0;
SDL_DisplayMode dm;
cout<<"Gobot call:";
gobot(&horizontal, &vertical, &dm);


In your .CPP Definition:

int gobot( int* horizontal, int* vertical, SDL_DisplayMode* dm )
   {
      //SDL_GetDesktopDisplayMode(0, &dm);
      *horizontal = dm->w;
      *vertical = dm->h;
      return 0;
   }
In your .H Declaration
int gobot( int* horizontal, int* vertical, SDL_DisplayMode* dm );

On Tue, Feb 7, 2017 at 5:20 PM, speartip <[hidden email]> wrote:

Hi,

I am struggling with some pretty straight forward c/c++ & SDL code. But I am not feeling the straightforwardness of it though. I don't know if its a c++ issue or SDL. I try to call SDL fx code from an external .cpp/.h. I am trying to make these reusable and to release main from clutter. Everything runs smoothly until the second block:





Code:



int horizontal = 0;
int vertical = 0;
SDL_DisplayMode dm;
cout<<"Gobot call:";
gobot(horizontal, vertical,&dm);







Code:



#ifndef GOBOT_CPP_
#define GOBOT_CPP_

#include "SDL.h"
#include "gobot.h"


int gobot( int &horizontal, int &vertical, &dm )
   {
      //SDL_GetDesktopDisplayMode(0, &dm);
      horizontal = dm->w;
      vertical = dm->h;
      return 0;
   }
   //cout<<"Resolution: x = "<


Code:



#ifndef GOBOT_H_
#define GOBOT_H_
#include"SDL.h"

int SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode * dm);
int gobot(int horizontal, int vertical, SDL_DisplayMode * dm);

#endif /* GOBOT_H_ */




error:
In function 'int SDL_main(int, char**)':
..\src\SpearTip.cpp:50:35: error: cannot convert 'SDL_DisplayMode' to 'SDL_DisplayMode*' for argument '3' to 'int gobot(int, int, SDL_DisplayMode*)'
gobot(horizontal, vertical, dm);

Thanks

_______________________________________________
SDL mailing list

_______________________________________________
SDL mailing list


_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|

Re: cannot convert 'SDL_DisplayMode' to 'SDL_DisplayMode*

speartip
In reply to this post by speartip
Deployed with changes; errors persistent:








Code:

 horizontal = 0; vertical = 0;
 SDL_DisplayMode dm;
 cout<<"Gobot call:";
 gobot(&horizontal,&vertical, &dm);









Code:

#include"SDL.h"

int SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode * dm);
int gobot( int * horizontal, int * vertical, SDL_DisplayMode * dm);









Code:

#include "SDL.h"
#include "gobot.h"


int gobot( int * horizontal, int* vertical, &dm )
   {
      //SDL_GetDesktopDisplayMode(0, &dm);
       *horizontal = dm->w;
       *vertical = dm->h;
      return 0;
   }


error:







Code:

.\src\gobot.cpp:15:45: error: 'dm' has not been declared
 int gobot( int * horizontal, int* vertical, dm )
                                             ^
..\src\gobot.cpp: In function 'int gobot(int*, int*, int)':
..\src\gobot.cpp:18:18: error: 'dm' was not declared in this scope
   * horizontal = dm->w;


_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|

Re: cannot convert 'SDL_DisplayMode' to 'SDL_DisplayMode*

Brian Puthuff

int gobot( int * horizontal, int* vertical, &dm )

   {
      //SDL_GetDesktopDisplayMode(0, &dm);
       *horizontal = dm->w;
       *vertical = dm->h;
      return 0;
   }

Should be:

int gobot( int * horizontal, int* vertical, SDL_DisplayMode* dm )
  {
      //SDL_GetDesktopDisplayMode(0, &dm);
       *horizontal = dm->w;
       *vertical = dm->h;
      return 0;
   }

That third argument is incorrect on that first version. The definition arguments need to match the declaration arguments. That third argument is a pointer to a structure. The only time you pass &dm is when you actually call the function. Not during declaration and definition. 


On Feb 8, 2017 4:08 PM, "speartip" <[hidden email]> wrote:
Deployed with changes; errors persistent:




Code:


 horizontal = 0; vertical = 0;

 SDL_DisplayMode dm;
 cout<<"Gobot call:";
 gobot(&horizontal,&vertical, &dm);







Code:


#include"SDL.h"

int SDL_GetDesktopDisplayMode(int displayIndex, SDL_DisplayMode * dm);
int gobot( int * horizontal, int * vertical, SDL_DisplayMode * dm);







Code:


#include "SDL.h"
#include "gobot.h"


int gobot( int * horizontal, int* vertical, &dm )

   {
      //SDL_GetDesktopDisplayMode(0, &dm);
       *horizontal = dm->w;
       *vertical = dm->h;
      return 0;
   }




error:



Code:


.\src\gobot.cpp:15:45: error: 'dm' has not been declared
 int gobot( int * horizontal, int* vertical, dm )
                                             ^
..\src\gobot.cpp: In function 'int gobot(int*, int*, int)':
..\src\gobot.cpp:18:18: error: 'dm' was not declared in this scope
   * horizontal = dm->w;




_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org



_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|

Re: cannot convert 'SDL_DisplayMode' to 'SDL_DisplayMode*

speartip
In reply to this post by speartip
Thank you Brian this is what it should have been. Always match your declarations and definitions!

Should be:







Code:

int gobot( int * horizontal, int* vertical, [b]SDL_DisplayMode* dm[/b] )


Works fine now. I did revert back to using pass by reference which simplified things a bit even though I know pointers are perfectly valid. So by using &var I could change the val in the subroutine without making a copy and keep the most up to date version in main.

Thank you![/code]

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|

Re: cannot convert 'SDL_DisplayMode' to 'SDL_DisplayMode*

speartip
In reply to this post by speartip
whooops








Code:


int gobot( int &horizontal, &vertical, SDL_DisplayMode * dm)


_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|

Re: cannot convert 'SDL_DisplayMode' to 'SDL_DisplayMode*

speartip
In reply to this post by speartip
Thank you Brian this is what it should have been. Always match your declarations and definitions!

Should be:
Code:

int gobot( int horizontal, int vertical, SDL_DisplayMode* dm )


Works fine now. I did revert back to using pass by reference which simplified things a bit even though I know pointers are perfectly valid. So by using &var I could change the val in the subroutine without making a copy and keep the most up to date version in main.

Thank you![/code]

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Reply | Threaded
Open this post in threaded view
|

Re: cannot convert 'SDL_DisplayMode' to 'SDL_DisplayMode*

speartip
In reply to this post by speartip
Thanks for solving that so quickly.ST

_______________________________________________
SDL mailing list
[hidden email]
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org