Click here to Skip to main content
15,922,533 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: Sorting Algorithm for C++ for an array Pin
CPallini27-Jul-08 21:38
mveCPallini27-Jul-08 21:38 
Questiondesignated initializer Pin
kcynic27-Jul-08 16:07
kcynic27-Jul-08 16:07 
AnswerRe: designated initializer Pin
Joe Woodbury27-Jul-08 16:22
professionalJoe Woodbury27-Jul-08 16:22 
QuestionADO .NET using c++ Pin
rp_suman27-Jul-08 15:51
rp_suman27-Jul-08 15:51 
AnswerRe: ADO .NET using c++ Pin
CPallini27-Jul-08 21:23
mveCPallini27-Jul-08 21:23 
QuestionI can build but cant run my program... Pin
xelios27-Jul-08 9:20
xelios27-Jul-08 9:20 
AnswerRe: I can build but cant run my program... Pin
hoxsiew27-Jul-08 15:41
hoxsiew27-Jul-08 15:41 
QuestionLinked List nodes don't recognise "Tile" (data) class. Pin
Sauce!27-Jul-08 3:05
Sauce!27-Jul-08 3:05 
Hi guys,

I've been working on my Linked List implementation and have run into some troubles. There is an easy solution (more on this later) but the problem is, it's a messy solution.

When I compile my project I get the following errors:

<project name="">\LinkedTileList.h(17) : error C2061: syntax error : identifier 'Tile'
<project name="">\LinkedTileList.h(24) : error C2061: syntax error : identifier 'Tile'
<project name="">\LinkedTileList.h(26) : error C2061: syntax error : identifier 'Tile'
<project name="">\LinkedTileList.h(29) : error C2143: syntax error : missing ';' before '*'
<project name="">\LinkedTileList.h(29) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
<project name="">\LinkedTileList.h(29) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
<project name="">\LinkedTileList.h(38) : error C2061: syntax error : identifier 'Tile'
<project name="">\LinkedTileList.h(48) : error C2061: syntax error : identifier 'Tile'
<project name="">\LinkedTileList.h(59) : error C2061: syntax error : identifier 'Tile'
</project></project></project></project></project></project></project></project></project>


It doesn't recognise my Tile class from within the Node class of my linked list.

Here is LinkedTileList.h
#pragma once
#ifndef INC_LINKEDLIST_H
#define INC_LINKEDLIST_H

#include "Globals.h"

class Node;
class HeadNode;
class TailNode;
class InternalNode;

class Node
{
public:
	Node();
	virtual ~Node();
	virtual Node * Insert(Tile * theTile)=0;
private:
};

class InternalNode: public Node
{
public:
	InternalNode(Tile * theTile, Node * next);
	virtual ~InternalNode();
	virtual Node * Insert(Tile * theTile);

private:
	Tile * myTile;
	Node * myNext;
};

class TailNode : public Node
{
public:
	TailNode();
	virtual ~TailNode();
	virtual Node * Insert(Tile * theTile);
	
private:
};

class HeadNode : public Node
{
public:
	HeadNode();
	virtual ~HeadNode();
	virtual Node * Insert(Tile * theTile);
	
private:
	Node * myNext;
};

class LinkedTileList
{
public:
	LinkedTileList();
	~LinkedTileList();
	void Insert(Tile * theTile);

private:
	HeadNode * myHead;
};

#endif


LinkedTileList.cpp
#include "Globals.h"
#include "LinkedTileList.h"

InternalNode::InternalNode(Tile * theTile, Node * next):
myTile(theTile), myNext(next)
{

}

InternalNode::~InternalNode()
{
	delete myNext; delete myTile;
}

Node * InternalNode::Insert(Tile * theTile)
{
	myNext = myNext->Insert(theTile);
	return this;
}

Node * TailNode::Insert(Tile * theTile)
{
	InternalNode * dataNode = new InternalNode(theTile, this);
	return dataNode;
}

HeadNode::HeadNode()
{
	myNext = new TailNode;
}

HeadNode::~HeadNode()
{
	delete myNext;
}

Node * HeadNode::Insert(Tile * theTile)
{
	myNext = myNext->Insert(theTile);
	return this;
}

LinkedTileList::LinkedTileList()
{
	myHead = new HeadNode;
}

LinkedTileList::~LinkedTileList()
{
	delete myHead;
}

void LinkedTileList::Insert(Tile * pTile)
{
	myHead->Insert(pTile);
}


Tile.h
#pragma once
#ifndef INC_TILE_H
#define INC_TILE_H

#include "Globals.h"

// Tracking pointer that counts the number of Tile's.
static int NumTiles = 0;
static int * p_iNumTiles = &NumTiles;

class Tile
{
	public:
		Tile(void);
		~Tile(void);

		float GetLeft(void);
		float GetTop(void);

		void SetLeft(float);
		void SetTop(float);
	
	private:
		float left;
		float top;
};

#endif


Tile.cpp
#include "Tile.h"

Tile::Tile(void)
{
	*p_iNumTiles++;
}

Tile::~Tile(void)
{
	*p_iNumTiles--;
}

float Tile::GetLeft(void)
{
	return left;
}

float Tile::GetTop(void)
{
	return top;
}

void Tile::SetLeft(float x)
{
	float * p_left = &this->left;
	*p_left = x;
}

void Tile::SetTop(float y)
{
	float * p_top = &this->top;
	*p_top = y;
}


Globals.h is pretty much my implementation of stdafx.h. It contains all header files for the project.

Now, for the "dirty" solution - all I have to do is cut the contents of Tile.h into the beginning of LinkedTileList.h and Tile.cpp into the beginning of LinkedTileList.cpp but you can probably tell why this feels dirty. The Tile class is used elsewhere in the project and I don't want to be making it so much a part of the LinkedTileList class, but just a resource that is available to it. Why isn't the preprocessor doing it's job? (And if it is doing it's job and I'm the one who stuffed up, then what am I doing wrong?)

Both the linked list and the tile class are far from finished but I can't go much further until I work out this problem. Frown | :(
AnswerRe: Linked List nodes don't recognise "Tile" (data) class. Pin
Luc Pattyn27-Jul-08 3:24
sitebuilderLuc Pattyn27-Jul-08 3:24 
GeneralRe: Linked List nodes don't recognise "Tile" (data) class. Pin
Sauce!27-Jul-08 3:31
Sauce!27-Jul-08 3:31 
GeneralRe: Linked List nodes don't recognise "Tile" (data) class. Pin
Luc Pattyn27-Jul-08 3:38
sitebuilderLuc Pattyn27-Jul-08 3:38 
GeneralRe: Linked List nodes don't recognise "Tile" (data) class. Pin
Cedric Moonen27-Jul-08 8:50
Cedric Moonen27-Jul-08 8:50 
GeneralRe: Linked List nodes don't recognise "Tile" (data) class. Pin
Sauce!27-Jul-08 15:46
Sauce!27-Jul-08 15:46 
QuestionTrouble with Releaser Version - Double selections in List Control = DOES NOT happen in Debug version Pin
Larry Mills Sr26-Jul-08 15:46
Larry Mills Sr26-Jul-08 15:46 
AnswerRe: Trouble with Releaser Version - Double selections in List Control = DOES NOT happen in Debug version Pin
Luc Pattyn26-Jul-08 16:05
sitebuilderLuc Pattyn26-Jul-08 16:05 
GeneralRe: Trouble with Releaser Version - Double selections in List Control = DOES NOT happen in Debug version Pin
Larry Mills Sr28-Jul-08 10:04
Larry Mills Sr28-Jul-08 10:04 
GeneralRe: Trouble with Releaser Version - Double selections in List Control = DOES NOT happen in Debug version Pin
Luc Pattyn28-Jul-08 10:17
sitebuilderLuc Pattyn28-Jul-08 10:17 
GeneralRe: Trouble with Releaser Version - Double selections in List Control = DOES NOT happen in Debug version Pin
Larry Mills Sr30-Jul-08 2:31
Larry Mills Sr30-Jul-08 2:31 
QuestionIs that sharing "memory" or sharing "file"? Pin
sawerr25-Jul-08 23:56
sawerr25-Jul-08 23:56 
AnswerRe: Is that sharing "memory" or sharing "file"? Pin
Luc Pattyn26-Jul-08 3:23
sitebuilderLuc Pattyn26-Jul-08 3:23 
AnswerRe: Is that sharing "memory" or sharing "file"? Pin
gayatri.neelema27-Jul-08 1:21
gayatri.neelema27-Jul-08 1:21 
Questionchanging device context. Pin
sanjutvm25-Jul-08 20:15
sanjutvm25-Jul-08 20:15 
AnswerRe: changing device context. Pin
CPallini25-Jul-08 21:37
mveCPallini25-Jul-08 21:37 
QuestionTreeCtrl with checkbox. Pin
Le@rner25-Jul-08 19:05
Le@rner25-Jul-08 19:05 
AnswerRe: TreeCtrl with checkbox. Pin
kDevloper25-Jul-08 20:04
kDevloper25-Jul-08 20:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.