Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Parse Issue  (Read 2761 times)

0 Members and 1 Guest are viewing this topic.

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Parse Issue
« on: March 04, 2013, 09:19:54 am »
I'm currently getting a problem that I honestly just cannot figure out.

I'm coding Space Invaders, everything was running fine until I started getting this parse issue.

I have tried re-creating the issue in another project but everything works fine when I try to do so.

I also tried re-creating the project incase the project file itself was corrupt or something, that also failed and I still get the issue.

Error message:


I really don't understand why it says 'Ship' is an unknown type, I #included "ship.h" in the projectile header file.

Below are links to the Projectile .cpp and header file, I'm pretty sure my code is accurate (It may not be perfect but it should run right?)

Projectile.cpp: http://pastebin.com/tsNhnWNA
Projectile.h (Getting the error on line 20): http://pastebin.com/Bef53YfE

I have also provided links to the ship .cpp and header files. As I said above I'm pretty sure the code is accurate for them also.

Ship.cpp: http://pastebin.com/a22nYNYB
Ship.h: http://pastebin.com/3m3zec3a

Sorry if this is a simple/annoying question but I really don't know where else to look, I have tried everything I can think of to try and solve this.

Thank you.
« Last Edit: March 04, 2013, 09:24:41 am by MarcuzPwnz »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10818
    • View Profile
    • development blog
    • Email
Re: Parse Issue
« Reply #1 on: March 04, 2013, 09:25:43 am »
Make sure that you're Projectile.h isn't saved as UTF-8 with BOM, I think XCode doesn't like that (at least that's what Google told me). ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: Parse Issue
« Reply #2 on: March 04, 2013, 09:29:13 am »
I would have no idea how to figure out if my file was saved liked that. I didn't mess with any save settings so I wouldn't understand why it would be saved like that to begin with. :P

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Parse Issue
« Reply #3 on: March 04, 2013, 09:29:27 am »
Ship.h includes AlienProjectile.h, which (most likely) includes Projectile.h, which includes Ship.h, which includes AlienProjectile.h, which includes Projectile.h, which includes Ship.h, which includes AlienProjectile.h, which includes Projectile.h, which includes Ship.h, which includes AlienProjectile.h, which includes Projectile.h, which includes Ship.h, which includes AlienProjectile.h, which includes Projectile.h, which...
Laurent Gomila - SFML developer

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: Parse Issue
« Reply #4 on: March 04, 2013, 09:34:52 am »
AlienProjectile.h doesn't include Projectile.h, but anyway, I'm really not sure how that was suppose to help.  ???

I'm guessing you were mocking the way I used classes or coded the game?
« Last Edit: March 04, 2013, 09:41:26 am by MarcuzPwnz »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10818
    • View Profile
    • development blog
    • Email
Re: Parse Issue
« Reply #5 on: March 04, 2013, 09:45:15 am »
No he showed the most probably thing, that you have circular inclusion somewhere, but since we have only two headers, he guessed.

You should delay the inclusion of headers as long as possible and use forward declarations instead (for references and pointers).
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Parse Issue
« Reply #6 on: March 04, 2013, 09:47:07 am »
Circular inclusions can lead to this kind of error ("type Xxx not declared"), because at the second loop, the compiler stops at the #ifndef and thus skips what's defined below. Sorry for being unclear.

Sometimes, circular inclusions are hard to track, because the inclusion chain can be quite long.
Laurent Gomila - SFML developer

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: Parse Issue
« Reply #7 on: March 04, 2013, 09:50:08 am »
Ohh I see, I will look into this in the morning, it's late and I have school tomorrow.

Thank you for the help, I really appreciate it, and it's not your fault it was unclear to me, I need to learn more. :P

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: Parse Issue
« Reply #8 on: March 04, 2013, 07:54:44 pm »
I have done a few Google searches and read your replies but I still don't 100% understand why this is occurring, Am I including something in the wrong place/too many times and causing the compiler to try and loop through the #includes in the header files? :)

I have links to all my header files below:
Ship: http://pastebin.com/7FjFW3Wu
Alien: http://pastebin.com/cwzfxN7i
Projectile: http://pastebin.com/UJ0gTGdt
AlienProjectile: http://pastebin.com/XFybiQ1a
HUD: http://pastebin.com/iKAfg1js
« Last Edit: March 04, 2013, 07:57:05 pm by MarcuzPwnz »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10818
    • View Profile
    • development blog
    • Email
Re: Parse Issue
« Reply #9 on: March 04, 2013, 08:02:33 pm »
Well Laurent was right. ;D

Ship includes AlienProjectile, which includes Projectile, which includes Ship, which includes AlienProjectile, which includes Projectile, which includes Ship, which includes AlienProjectile, which includes Projectile, which includes Ship, which includes AlienProjectile, which includes Projectile, which includes Ship, which includes AlienProjectile, which includes Projectile, which includes Ship, which includes AlienProjectile, which includes Projectile, which includes Ship, which includes AlienProjectile, which includes Projectile, which includes Ship, which includes AlienProjectile, which includes Projectile, which includes Ship, which includes AlienProjectile, which includes Projectile........... ;D

The way to solve this, is to forward declare stuff you're only referencing in the header.
For instace Projectile only uses a reference to Ship in its header, so instead of the #include "Ship.h" you write class Ship;, which tells the compiler: "Hey I'll be defining this class later on."

The same would apply for the Projectile in AlienProjectile etc.
Just google for "forward deceleration" or better look it up in a good C++ book.

Btw. you should never put using namespace xyz; in a header file, well in mostly all cases you shouldn't be using namespace anyways. Namespaces are very useful, since they tell exactly from where the function originates from and prevent name clashes.
« Last Edit: March 04, 2013, 08:04:35 pm by eXpl0it3r »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

MarcuzPwnz

  • Jr. Member
  • **
  • Posts: 77
    • View Profile
Re: Parse Issue
« Reply #10 on: March 04, 2013, 10:24:58 pm »
Thank you very much! I'm in school at the moment but I will fix this up once I get home. I will also do as you recommended and look up forward deceleration in a C++ book I have at home.

Thanks again, I have learned a lot of new things with the help from you two. :D

Edit: Arrived home and did some reading and editing of my code, working perfectly again! Thank you!
« Last Edit: March 05, 2013, 04:53:36 am by MarcuzPwnz »