Hi guys and girls,

I've decided to pick up C++ again after not using it for 2 nearly 3 years.
I've been programming in java and c# in the mean time so my understanding of programming is very good.

I've been trying to make a pack of cards but for some reason I can't understand the error im getting.

card header and class file:

#include <iostream>
using namespace std;

class Card
{
public:
	enum Values{Ace,Two,Three,Four,Five,Six,Seven,Eight,Nine,Ten,Jack,Queen,King};
	enum Suits{Hearts,Clubs,Diamonds,Spades};
	Card();
	Card(Suits newSuit, Values newValue);
	string returnSuit();
	string returnValue();
	string printCard();
	char* suitString[4];
	char* valueString[13];

private:
	
	Values value;
	Suits suit;
};

#include "Card.h"
#include <iostream>
using namespace std;

Card::Card(Suits newFace, Values newValue)
{
	suit = newFace;
	value = newValue;
}
string Card::returnSuit()
{
	char* suitString[4] =  {"Hearts", "Clubs", "Diamonds", "Spades"};
	return suitString[suit];
}
string Card::returnValue()
{
	char* valueString[13] = {"Ace","Two","Three","Four","Five","Six","Seven","Eight","Nine","Ten","Jack","Queen","King"};
	return valueString[value];
}
string Card::printCard()
{
	string temp = returnValue().append(" of ");
	string tempo = returnSuit().c_str();
	string final = temp.append(tempo).c_str();
	return final;
}
Card::Card()
{
	suit = Card::Suits::Hearts;
	value = Card::Values::Ace;
}

This is working fine.

but when i add my deck class I suddely get an error

#include "Card.h"
using namespace std;
class Deck
{
public:
	Deck();
	Card cardAt(int pos);
	Card *deck[52];
}


#include "Deck.h"
#include "Card.h"
using namespace std;

Deck::Deck()
{
	int i = 0;
}

Now i know the constructor of Deck does nothing. But I can't get it to compile even with that code.

the error it throws when compiling is:
1>c:\visual studio\projects\blackjack\blackjack\card.h(2): error C2143: syntax error : missing ';' before 'using'
1>c:\visual studio\projects\blackjack\blackjack\card.h(5): error C2011: 'Card' : 'class' type redefinition
1> c:\visual studio\projects\blackjack\blackjack\card.h(5) : see declaration of 'Card'

If i comment out my Deck.cpp then it compiles.

Any help is much appreciated.

Notice anything missing???

class Deck
{
public:
	Deck();
	Card cardAt(int pos);
	Card *deck[52];
}  //<---????

Yes that was retarded of me to miss something so simple.

but unfortunly that only removed the first error out of the 3.

so know left with:
1>c:\visual studio\projects\blackjack\blackjack\card.h(5): error C2011: 'Card' : 'class' type redefinition
1> c:\visual studio\projects\blackjack\blackjack\card.h(5) : see declaration of 'Card'

Well, your code blocks don't look like they match your actual code distribution throughout your files. From what I can tell, you are probably running into multi-include issues. You'll have to add header guards to your card.h file.

//sample.h

#ifndef SAMPLE_H
#define SAMPLE_H

class Sample {
 //...
};

#endif //SAMPLE_H

Edited 5 Years Ago by Fbody: n/a

Thank you.

Adding the

#ifndef SAMPLE_H
#define SAMPLE_H
.
.
.
.
#endif //SAMPLE_H

in my Card.cpp class fixed the error :)

Be cautious about how you do it. What I posted was just an example. You need to be sure that you put a unique guard in each of your header files, otherwise they won't work correctly. Here's some more information.

In general, the identifier used as a header guard should be the same as your file's name (i.e. "card.h"). Therefore, for your Card header, your header guards should be more like this:

//Card.h
#ifndef CARD_H
#define CARD_H

class Card {

};

#endif  //CARD_H

Yea I did change the header guards to match my class names.

Thanks for the link as well.

This question has already been answered. Start a new discussion instead.