7 Replies - 496 Views - Last Post: 25 August 2011 - 03:39 PM Rate Topic: -----

#1 Java Student  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 483
  • Joined: 05-February 10

Passing arguments

Posted 25 August 2011 - 12:13 AM

Hello, im following lazyfoo's tutorials and im trying to seperate his multiple classes in one main file into header and cpp files. I have done this before but trouble came up when SDL functions were getting in the way.

I,ll try to make this really straight forward. I'm calling a Dot.cpp function from my main and it takes 1 argument which is a SDL_event type and i dont know how to pass it by reference.

[see attachment 1] This shows the error when i try to compile.
[see attachment 2] This shows the function and how im 'trying' to pass-by-ref

Help is greatly appreciated!

Attached image(s)

  • Attached Image
  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Passing arguments

#2 sarmanu  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 966
  • View blog
  • Posts: 2,362
  • Joined: 04-December 09

Re: Passing arguments

Posted 25 August 2011 - 01:37 AM

Check the declaration of handle_input in Dot.h
Was This Post Helpful? 1
  • +
  • -

#3 Java Student  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 483
  • Joined: 05-February 10

Re: Passing arguments

Posted 25 August 2011 - 02:19 AM

Fail. I gotta remember to check the prototype more often.
I supposedly fixed the problem but evidently not because my complier is mad at
me again.

[see attachment 1 (dot.h)] You can see i 'fixed' the problem (from void handle_input(); --> void handle_input(SDL_Event*); ), but it shows another error.
[see attachment 2 (dot.cpp)] Nothing changed. This is the function.
[see attachment 3 (main.cpp)] Nothing changed. This is where its called.

Attached image(s)

  • Attached Image
  • Attached Image
  • Attached Image

This post has been edited by Java Student: 25 August 2011 - 02:24 AM

Was This Post Helpful? 0
  • +
  • -

#4 jimblumberg  Icon User is offline

  • member icon


Reputation: 4278
  • View blog
  • Posts: 13,437
  • Joined: 25-December 09

Re: Passing arguments

Posted 25 August 2011 - 05:55 AM

Please post the error messages, cut and paste from your development environment, exactly as they appear. Along with the code causing the problems. This way we can see the problem and possibly aid in fixing them. The screen shots are too hard to read and I can not compile a screen shot.


Jim
Was This Post Helpful? 2
  • +
  • -

#5 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,659
  • Joined: 23-August 08

Re: Passing arguments

Posted 25 August 2011 - 06:17 AM

At the point you refer to SDL_Event in "Dot.h", the compiler has no idea what SDL_Event is. Include the SDL headers in "Dot.h", rather than "Dot.cpp".
Was This Post Helpful? 1
  • +
  • -

#6 Java Student  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 483
  • Joined: 05-February 10

Re: Passing arguments

Posted 25 August 2011 - 01:16 PM

Thanks Jack i think you hit the nail on the head with that one ;)

I added the headers to dot.h and it stopped complaing about that issue =)

I looks like im close to done but now its telling me that 'type' in
SDL_event.type isn't declared in SDL_event, but it really is according to the docs (http://sdl.beuc.net/sdl.wiki/SDL_Event).

Attached image(s)

  • Attached Image

This post has been edited by Java Student: 25 August 2011 - 01:17 PM

Was This Post Helpful? 0
  • +
  • -

#7 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6107
  • View blog
  • Posts: 23,659
  • Joined: 23-August 08

Re: Passing arguments

Posted 25 August 2011 - 02:45 PM

You need to go back to basics before you start messing with games, I think.

Your SDL_Event argument is a POINTER. How does one access a struct member through a pointer?
Was This Post Helpful? 2
  • +
  • -

#8 Java Student  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 21
  • View blog
  • Posts: 483
  • Joined: 05-February 10

Re: Passing arguments

Posted 25 August 2011 - 03:39 PM

Oh right "->" for pointers, im still learning the ways of c++ but im learning alot.
Thanks, that solved my problem. I'm really trying to wrap my head around c++ because
uni. starts in 2 weeks. Thanks Jack! :sweatdrop:
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1