0

As far as I could find out, C++ is not recognising my Unit class. I am sure I included it correctly in my GameMaster.h . I tried forward declaring but it had no effect. It seems to be linked correctly with makefile. Where could the error lie?

GameMaster.cpp:21:34: error: expected primary-expression before ‘*’ token
if (combatHandler.isEnemies(Unit* attackingUnit, Unit* defendingUnit))

code:

 if (combatHandler.isEnemies(Unit* attackingUnit, Unit* defendingUnit))
  • What does the header file look like? maybe there is a namespace or conditional compilation at play. – Soren Oct 18 '15 at 18:21
  • If it's not overbearing could you include the header and cpp file. At least the cpp file will give some more context to your issue. I don't think this is enough to help you on this problem. – GDub Oct 18 '15 at 18:21
  • 1. Do you include the header file in your source? 2. Does the header file of the `Unit` class have a **unique** `#ifndef`/`#define` guard macro name? – msmith81886 Oct 18 '15 at 18:23
  • 2
    Is `Unit` a class? Why are you declaring variables in a function call? Maybe you should check out some beginners tutorial or book from [The Definitive C++ Book Guide and List](http://stackoverflow.com/questions/388242/the-definitive-c-book-guide-and-list)? – Some programmer dude Oct 18 '15 at 18:23
  • Thanks for all your time and minds. I noticed it was an absolute rookie mistake.. I declared attackingUnit and defendingUnit previously in the function void GameMaster::attackUnit(Unit* attackingUnit, Unit* defendingUnit) and thus the redeclaration of the Unit* is useless.. I should have just removed the Unit* part.. so daft of me.. Joachim and Bo are correct. Should I delete the question or just leave it? – Bernard van Tonder Oct 18 '15 at 18:31
  • It's a valid question that was well made. Just because it's over something silly doesn't mean you should delete or close it. Others will make this mistake and come here looking for an answer. Besides, you can't delete a question if there's been an answer. Only mods can do that. – Edward Strange Oct 18 '15 at 18:41
  • @CrazyEddie: It's not going to be of much use to anyone else, hence impending closure. – Lightness Races in Orbit Oct 18 '15 at 19:08

1 Answers1

4

When you are calling the functions, you should not give the parameter types, just their values. Perhaps like this

if (combatHandler.isEnemies(&attackingUnit, &defendingUnit))
Bo Persson
  • 90,663
  • 31
  • 146
  • 203