Hello! I'm trying to make Solitaire and I'm running into a compile problem. I have a class called Input and I have a class called Game. Whenever I try to pass an Input Object to a Game function, I get this error:
game.h(19): error C2061: syntax error : identifier 'Input'
game.h(20): error C2061: syntax error : identifier 'Input'
main.cpp(57): error C2660: 'Game::nextThreeCards' : function does not take 3 arguments
If I remove that parameter from the functions, it'll compile just fine, but that's not really a solution. I did some googling and apparently this might be caused by circular logic (ie: Input object needs the game object and game object needs the input object), but I'm not really sure. What I read said that you could fix that by passing in a reference, but I tried that and the error still happens.
These are the two classes
game.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
|
#ifndef GAME_H
#define GAME_H
#include "card.h"
#include "constants.h"
#include "input.h"
class Game
{
private:
int BeingDraggedFromyValue;
int BeingDraggedFromxValue;
public:
Game();
void initialPlaceCardsOnScreen(Card *aDeck);
void addSpacingInyValueOfRows(Card *aDeck);
void DetermineAndSetIfCardShouldBeFaceUp(Card *aDeck);
void nextThreeCards(Input& anInputObject, Card *aDeck, Card BackOfCard);
void MoveSpriteBack(Card *aDeck, Input anInputObject);
void setBeingDraggedFromyValue(int value);
void setBeingDraggedFromxValue(int value);
int getBeingDraggedFromyValue();
int getBeingDraggedFromxValue();
};
#endif
|
input.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
|
#ifndef INPUT_H
#define INPUT_H
#include "SDL.h"
#include "card.h"
#include "game.h"
#include "constants.h"
class Input
{
private:
int CurrentMousex, CurrentMousey, OldMousex, OldMousey, ChangeInMousex, ChangeInMousey;
int WhichSpriteIsBeingDragged;
bool IsLeftClickHeldDown;
bool LeftClickReleased;
SDL_Event event;
public:
Input();
void readInput(bool &quit, Card *aDeck);
void dragSprite(bool &quit, Card *aDeck);
int getWhichSpriteIsBeingDragged();
bool getIsLeftClickHeldDown();
int getCurrentMousex();
int getCurrentMousey();
bool getLeftClickReleased();
void setLeftClickReleased(bool value);
};
#endif
|
And these are the functions that I tried it with.
This is nextThreeCards()
1 2 3 4 5 6 7 8 9 10 11 12 13
|
void Game::nextThreeCards(Input& anInputObject, Card *aDeck, Card BackOfCard)
{
SDL_Rect BoundingRegion;
if (anInputObject.getIsLeftClickHeldDown() == true)
{
//If there is no sprite being dragged, check if we should start dragging a sprite
for (int i = 0; i < ARRAY_NUMBER_OF_CARDS_IN_DECK; i++)
{
BoundingRegion = BackOfCard.getBoundingRegion();
//if statement to check if we clicked inside the bounding box here
}
}
}
|
And MoveSpriteBack
1 2 3 4 5 6 7 8 9 10 11 12 13
|
void Game::MoveSpriteBack(Card *aDeck, Input anInputObject)
{
if (anInputObject.getLeftClickReleased() == 1)
{
int DeckIndex = 0;
while (DeckIndex <= ARRAY_NUMBER_OF_CARDS_IN_DECK)
{
DeckIndex++;
}
anInputObject.setLeftClickReleased(0);
}
}
|
As you can see, those functions literally do nothing right now, as I was writing them when I got this compile error. Microsoft says the following about this error --
"The compiler found an identifier where it wasn't expected. Make sure that identifier is declared before you use it.
An initializer may be enclosed by parentheses. To avoid this problem, enclose the declarator in parentheses or make it a typedef.
This error could also be caused when the compiler detects an expression as a class template argument; use typename to tell the compiler it is a type."
If anyone could offer me some help or advice, I'd greatly appreciate it.