Jump to content
  • Advertisement
Sign in to follow this  
dcuk

linked list problem

This topic is 4825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hiya, had several compiler errors, and im wracking my brain for why so gathered best place would be here, i was just experimenting with linkedlists to further learning, if it did compile still wouldn't be finished, but really shouldn't be any problems with this code..!?!
 
#include <iostream>
#include <Windows.h>

int main() {
	int temp;
	std::cin>>temp;
	system("pause");
}


class Node;
class HeadNode;
class TailNode;
class Internal;


enum Result {
	IsSmaller=0,
	IsBigger=1,
	IsEqual=2
};
class LinkedList {
	LinkedList();
	~LinkedList() {}
};

LinkedList::LinkedList() {
	HeadNode * MyHead = new HeadNode();
}

class HeadNode :Node{
public:
	HeadNode();
private:
	Node * MyNext;
};

HeadNode::HeadNode() {
	MyNext = TailNode * MyTail = new TailNode();
}

class TailNode :Node {
	TailNode();
};

TailNode::TailNode() {

}

class Internal :Node{
	Internal(Data const &, Node next);
	Insert();

private:
	Data * MyData;
	Node * MyNext;
};

Internal::Insert() {

}

Internal::Internal(Data const & other, Node next) {
	MyData = other.pData;
	MyNext = next;
}

class Data {
public:
	Data() { pData = rand(); }
	Compare(Data const &);
private:
	int pData;
	}
};

Data::Compare(Data const & other) {
	if(other.pData > pData)
		return IsBigger;
	if(other.pData < pData)
		return IsSmaller;

	if(other.pData == pData)
		return IsEqual;
}

class Node :public Data{
	virtual void Show();
private:
	Data * MyData;
};


Error messages: c:\Program Files\Microsoft Visual Studio\MyProjects\LinkedList\LinkedList.cpp(28) : error C2512: 'HeadNode' : no appropriate default constructor available c:\Program Files\Microsoft Visual Studio\MyProjects\LinkedList\LinkedList.cpp(31) : error C2504: 'Node' : base class undefined c:\Program Files\Microsoft Visual Studio\MyProjects\LinkedList\LinkedList.cpp(39) : error C2065: 'MyTail' : undeclared identifier c:\Program Files\Microsoft Visual Studio\MyProjects\LinkedList\LinkedList.cpp(39) : error C2275: 'TailNode' : illegal use of this type as an expression c:\Program Files\Microsoft Visual Studio\MyProjects\LinkedList\LinkedList.cpp(13) : see declaration of 'TailNode' c:\Program Files\Microsoft Visual Studio\MyProjects\LinkedList\LinkedList.cpp(39) : error C2512: 'TailNode' : no appropriate default constructor available c:\Program Files\Microsoft Visual Studio\MyProjects\LinkedList\LinkedList.cpp(42) : error C2504: 'Node' : base class undefined c:\Program Files\Microsoft Visual Studio\MyProjects\LinkedList\LinkedList.cpp(50) : error C2504: 'Node' : base class undefined must be something the way i have defined the classes.? [Edited by - dcuk on August 30, 2005 11:38:29 AM]

Share this post


Link to post
Share on other sites
Advertisement
The problem is that you are defining some of classes after their definitions are needed. If you have a class A and want to declare A* pointer or A& reference all you need is a declaration of class A, which you already have (class A;). However, if you are going to inherit from a class A, class A must already be defined, the declaration is not enough.

So, looking down at your code your class HeadNode tries to inherit from Node when Node is not defined yet. Place the definition of Node before the definition of HeadNode. Look through the rest of your code and verify that you have defined classes before trying to inherit from them or make objects of them.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!