i think i have some errors with inheritance and templates

#ifndef DECK_H
#define DECK_H

#include <random>
#include <string>
#include <vector>
#include "LQueue.h"

class Deck : public LQueue<Card>
{
public:
Deck();
bool isEmpty();
Card draw();
int getSize();
// void shuffle();
LQueue<Card> cards;
private:

int size;


};

#endif // DECK_H

//new file deck.cpp

#include <iostream>
#include "Card.h"
#include "LQueue.h"
#include "Deck.h"
#include <string>
#include <random>
#include <cstdlib>
#include <ctime>

Deck::Deck()
{
this -> size = 52;
// shuffle();
this -> cards = cards;
}
int Deck ::getSize()
{
return this -> size;
}
bool Deck::isEmpty()
{
if(size == 0){return true;}
return false;
}
Card Deck::draw()
{
size--;
return cards.dequeue();
}



//new header file
#ifndef LQUEUE_H
#define LQUEUE_H

#include "Card.h"
#include "Node.h"
template <class T>
class LQueue
{
public:
LQueue();
void enqueue(T data);
T dequeue();
bool isEmpty();

private:
Node<T> Front;
Node<T> End;

};

#endif // LQUEUE_H

//new file

#include "LQueue.h"
#include "Card.h"
#include "Node.h"
template <class T>
LQueue<T> ::LQueue()
{
this.Front = new Node<T>(NULL, NULL);
this.End = new Node<T>(NULL, Front);
this.Front.next = End;
}

template <class T>
void LQueue<T>::enqueue(T data)
{
Node<T> temp= new Node<T>(data, Front.next);
Front.next = temp;
End.next = temp;
}
template <class T>
T LQueue<T>::dequeue()
{
if (!isEmpty())
{
Card temp = Front.next.data;
Front.next = Front.next.next;
End.next = Front.next;
return temp;
}
}
template <class T>
bool LQueue<T>::isEmpty()
{
if (Front.next.data == NULL)
{
return true;
}
return false;
}

Error messages


||=== Build: Debug in Crazy8 (compiler: GNU GCC Compiler) ===|
obj\Debug\src\Deck.o||In function `ZN4DeckC2Ev':|
D:\crazy8c++\Crazy8\src\Deck.cpp|10|undefined reference to `LQueue<Card>::LQueue()'|
D:\crazy8c++\Crazy8\src\Deck.cpp|10|undefined reference to `LQueue<Card>::LQueue()'|
obj\Debug\src\Deck.o||In function `ZN4Deck4drawEv':|
D:\crazy8c++\Crazy8\src\Deck.cpp|28|undefined reference to `LQueue<Card>::dequeue()'|
obj\Debug\src\Hand.o||In function `ZN4Hand7canPlayE4CardS0_':|
D:\crazy8c++\Crazy8\src\Hand.cpp|46|undefined reference to `Hand::Equals(std::string, std::string)'|
D:\crazy8c++\Crazy8\src\Hand.cpp|50|undefined reference to `Hand::Equals(std::string, std::string)'|
D:\crazy8c++\Crazy8\src\Hand.cpp|54|undefined reference to `Hand::Equals(std::string, std::string)'|
||=== Build failed: 6 error(s), 0 warning(s) (0 minute(s), 0 second(s)) ===|

D:\crazy8c++\Crazy8\src\Deck.cpp|10|undefined reference to `LQueue<Card>::LQueue()'|

That's a linker error telling you that you have not implemented the constructor for the templated class.

D:\crazy8c++\Crazy8\src\Deck.cpp|28|undefined reference to `LQueue<Card>::dequeue()'|
obj\Debug\src\Hand.o||In function `ZN4Hand7canPlayE4CardS0_':|

That's a linker error telling you that you have not implemented the dequeue method for the templated class.

D:\crazy8c++\Crazy8\src\Hand.cpp|46|undefined reference to `Hand::Equals(std::string, std::string)'|

That's a linker error telling you that you have not implemented the Equals method for the Hand class.

Not sure what "new file" is supposed to be. In any case, you're declaring templated functions. You're not implementing anything in the file.

PLEASE USE CODE TAGS (the <> formatting button) when posting code.
It makes it easier to read your code and also easier to respond to your post.
http://www.cplusplus.com/articles/jEywvCM9/
Hint: You can edit your post, highlight your code and press the <> formatting button.



Topic archived. No new replies allowed.