質問

I actually answered my own question, which is what led to this question. All I was doing was trying to instantiate my Hands class in another file. I had many other classes being instantiated no problem. Except with my Hands instance it said that I was missing a type specifier, and said I was missing a ";" when I wasn't.

I was literally copying + pasting code from my Hands.h file to paste in a SO question, when I realized that my Hands.h class was the ONLY class that I was #include-ing from my State.h. (In my State.h I am #include-ing almost all classes). So I looked at every other .h file that I was instantiating from in my State.h, when I realized the only one was Hands.h. So I figured I would try to take out the #include State.h from my Hands.h and see what happens, and my errors go away. I'm just wondering why the hell that would matter if I was #include-ing Hands.h from State.h, and State.h from Hands.h

Hands.h

#include "Aesthetics.h"
#include "GamePlay.h"
#include "Checks.h"
#include "Poker.h"
#include "Deck.h"
#include "DrawCard.h"
//#include "State.h //<--- what I commented out, and it worked

State.h

#include "Hands.h"
#include "Aesthetics.h"
#include "GamePlay.h"
#include "Checks.h"
#include "Poker.h"
#include "Deck.h"
#include "DrawCard.h"
役に立ちましたか?

解決

You have two way to handle this issue:

1) Add some preprocessor lines to avoid multiple include of same header:

#ifndef __HANDS_H__
#define __HANDS_H__

// here your code

#endif

and similar for State.h

2) Add a pragma directive on top of your headers:

#pragma once

The second one is not part of the c++ standard but is implemented in many compilers (gcc, vs, llvm).

I hope this can help you.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top