inheritance

Hi guys
I am making a "five hand draw" poker game using inheritance.
I've previously made a linked list now I need to inherit(maybe spelling mistake :) from previously created Node class to create Card class.

This is what I've done so far. But I get few errors like:

card.h:15:1: error: expected class-name before ‘{’ token
card.h:18:2: error: ‘string’ does not name a type
card.h:19:3: error: ‘string’ does not name a type
card.cpp: In constructor ‘Card::Card()’:
card.cpp:15:2: error: ‘fRank’ was not declared in this scope
card.cpp:16:2: error: ‘fSuit’ was not declared in this scope
card.cpp: In member function ‘void Card::print()’:
card.cpp:25:10: error: ‘fRank’ was not declared in this scope
card.cpp:25:28: error: ‘fSuit’ was not declared in this scope
make: *** [card.o] Error 1

Thanks in advance.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#ifndef NODES_H_
#define NODES_H_


namespace CppLists{
class Node
{
public:
	Node();
        virtual ~Node();

	int fItem;
	Node *fNext;
	Node *fPrevious;
};
}

#endif /* NODES_H_ */



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
#include "Node.h"

using namespace std;
namespace CppLists{

	Node::Node(){

		fItem = 0;
		fNext = 0;
		fPrevious = 0;

	}
	Node::~Node(){}
}



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include "card.h"


using namespace std;

Card::Card(){
	fRank = "";
	fSuit = "";

}

Card::~Card(){
}

void Card::print()
{
	cout << fRank << " of " <<fSuit <<endl;
}



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17

#ifndef CARD_H_
#define CARD_H_

#include "Node.h"
#include <string>

class Card : public Node
{
public:
	Card();
	string fSuit;
		string fRank;
	virtual ~Card();

	void print();
};
Use std::string rather than just string. And #include <string> .
Last edited on


thanks for the reply.

But inheritance is still not working. I still get this error.
card.h:15:1: error: expected class-name before ‘{’ token
Your Node is in the namespace CppLists. So you need to refer to it as CppLists::Node outside that namespace:

1
2
3
class Card : public CppLists::Node
{
    // ... etc 
Thanks a lot mate!
so silly mistake :P
Topic archived. No new replies allowed.