Hi guys
I''m a new C++ programmer and I am having a few problems with some structs that I have defined in my header file and want to use in my CPP file. The struct called "deck" is defined in a file called "Cards.h". In the corresponding CPP file called "Cards.cpp" when I try to use the struct "deck", I get a lot of errors from the compiler as displayed in my compiler errors below. I have tried all manner of things including defing variables without the scope ie.. deck dec; in the cpp file but nothing seems to work. I was hoping one of you guys will point out to me if there is something that I'm doing wrong cos I cannot see it. Also, one other thing, If I define a namespace in my header file, am I able to use it in my cpp file? I'm only asking this cos I have defined a name called "pack" in my header file but when I try to use it in my cpp file, get an error saying that "pack is not s namespace name" as is illustrated in my compiler errors. I am using mingw 3.4.5. Please Help!!!
The Header file
Compiler Errors:
**** Build of configuration Debug for project Poker ****
**** Internal Builder is used for build ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -oCards.o ..\Cards.cpp
..\Cards.cpp:9: error: `pack' is not a namespace-name
..\Cards.cpp:9: error: expected namespace-name before ';' token
..\Cards.cpp:20 :2: warning: "/*" within comment
..\Cards.cpp:46 : error: expected `;' before "getCard"
..\Cards.cpp:47 : error: expected `;' before "dec"
..\Cards.cpp:63 : error: expected constructor, destructor, or type conversion before "Cards"
Build error occurred, build is stopped
Time consumed: 14359 ms.
I''m a new C++ programmer and I am having a few problems with some structs that I have defined in my header file and want to use in my CPP file. The struct called "deck" is defined in a file called "Cards.h". In the corresponding CPP file called "Cards.cpp" when I try to use the struct "deck", I get a lot of errors from the compiler as displayed in my compiler errors below. I have tried all manner of things including defing variables without the scope ie.. deck dec; in the cpp file but nothing seems to work. I was hoping one of you guys will point out to me if there is something that I'm doing wrong cos I cannot see it. Also, one other thing, If I define a namespace in my header file, am I able to use it in my cpp file? I'm only asking this cos I have defined a name called "pack" in my header file but when I try to use it in my cpp file, get an error saying that "pack is not s namespace name" as is illustrated in my compiler errors. I am using mingw 3.4.5. Please Help!!!
The Header file
Code:
#ifndef CARDS_H_
#define CARDS_H_
#include <iostream>
#include <string>
#include <vector>
namespace pack{
typedef struct sample
{
int a;
char b, c;
}
SAMPLE_STRUCT;
//////
}
class Cards
{
public:
Cards();
virtual ~Cards();
struct deck{
// this holds the description of the card e.g. "King Of"
string card_name;
//card type e.g. "Hearts", Spades, etc
string card_type;
/*
* the value of the card e.g, 2,3 6 etc Note that Jack = 10
* Queen = 11, King = 12, Ace = 13
*/
int card_value;
};
deck getCard();
};
#endif /*CARDS_H_*/
the cpp file
#include "Cards.h"
#include <iostream>
#include <vector>
using namespace std;
using namespace pack;
class Cards{
public:
Cards();
~Cards();
Cards::deck getCard();
Cards::deck dec;
};
Cards::Cards()
{
}
Cards::~Cards()
{
}
Cards::deck Cards::getCard(){
}
**** Build of configuration Debug for project Poker ****
**** Internal Builder is used for build ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -oCards.o ..\Cards.cpp
..\Cards.cpp:9: error: `pack' is not a namespace-name
..\Cards.cpp:9: error: expected namespace-name before ';' token
..\Cards.cpp:20 :2: warning: "/*" within comment
..\Cards.cpp:46 : error: expected `;' before "getCard"
..\Cards.cpp:47 : error: expected `;' before "dec"
..\Cards.cpp:63 : error: expected constructor, destructor, or type conversion before "Cards"
Build error occurred, build is stopped
Time consumed: 14359 ms.
Comment