Sign in to follow this  

linked list problem

This topic is 4493 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
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

This topic is 4493 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this