Hej!
Har stött på ett problem här när jag försöker länka mina klasser. Jag har gjort det förut och jag har ungefär samma syntax som i min andra fil men det blir massa error, vilket gör mig galen. Inkluderar jag "lottorow.h" i lottoCoupon.h och "LottoCoupon.h" i LottoRow.h får jag error "Includes itself". Tar jag bort det så får jag felmeddelande när jag försöker använda mig utav en variabel i LottoCoupon i LottoRow. Sätter jag däremot dit båda includes:en så funkar det perfekt, men då vägrar den kompilera för att den inkluderar sig själv?
LottoCoupon.h
Kod:
#ifndef LOTTO_COUPON_H
#define LOTTO_COUPON_H
class LottoCoupon
{
private:
LottoRow myRows[];
static const int maxNrOfRows = 10;
public:
LottoCoupon();
~LottoCoupon();
bool tip(int rowNr, int nr);
int getNrOfMarked(int rowNr);
int nrOfEqualNumbers(LottoRow theRow, int rowNr);
void showRow(int rowNr);
int getNrOfCompletedRows()const;
string toString()const;
};
#endif
LottoRow.h
Kod:
#ifndef LOTTO_ROW_H
#define LOTTO_ROW_H
#include <string>
#include <ctime>
using namespace std;
class LottoRow
{
private:
static bool row[];
int nrOfMarked;
static const int totalNrOnRow = 7;
static const int minValue = 1;
static const int maxValue = 35;
public:
LottoRow();
~LottoRow();
bool tip(int nr);
int nrOfEqualNumbers(LottoRow theRow);
void showRow()const;
int getNrOfMarked()const;
string toString()const;
};
#endif
LottoRow.cpp (Har inkluderat både lottoRow.h och lottoCoupon.h
Kod:
bool LottoRow :: tip(int theNr)
{
bool check = false;
if(nrOfMarked > 0)
{
for(int i = 0; i < nrOfMarked; i++)
{
if(myRows[i] = theNr) // Felmeddelande
{
check = true;
}
}
}
if(check == false)
{
myRows[nrOfMarked] = theNr; //"Undefined" (utan #include i .h filerna)
nrOfMarked++;
}
return check;
}