Classes Help

Error Help(urgent)

Page 1 of 1

1 Replies - 469 Views - Last Post: 25 October 2009 - 11:04 AM Rate Topic: -----

#1 trickysert  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 22-October 09

Classes Help

Post icon  Posted 25 October 2009 - 10:43 AM

list.h

#pragma once
#include "node.h"
class list
{
public:
	list(void);
	void insertatfirst(int);
	void insertatlast(int);
	void removeF(int &);
	void removeL(int &);
	bool Emty() const;
	void print() const;
	~list(void);
private:
//error error C2143: syntax error : missing ';' before '*'
	node * First;   //error here error C4430: missing type specifier - int assumed.
 	node * Last;   ////error here error C4430: missing type specifier - int assumed.
	
};



//list.cpp


#include "StdAfx.h"
#include "list.h"
#include "node.h"

using namespace std;

list::list(void)
{
}

list::insertatfirst(int d){
if(First == 0)
First=Last = new node(data,0);
else{
	node *tmp= new node(d,0);
	tmp->ptr=First;
	First=tmp;
}
}

list::insertatlast(int d){
node *tmp = new node(d);
if(Last == 0)
First=Last=tmp;
else{
Last->ptr = tmp;
Last = tmp;
}
}


bool list::removeF(int &d){
if(First==0)
return false;
else{
d = First->data;
node *tmp = First;
First = First->ptr;
delete tmp;
return true;
}
}


bool list::removeL(int &d){
if(Last==0)
return false;
d=Last->data;
if(First==Last){
delete First;
First = Last = 0;
}
else{
	node *tmp = First;
	while(tmp->ptr != Last)
		tmp = tmp->ptr;
	Last = tmp;
	delete Last->ptr;
	return true;
}
}

bool list::Emty() const{
return (First ==0);
}

void list::print()const{
node *tmp=First;
while(tmp != 0){
cout<<tmp->data;
tmp=tmp->ptr;
}
}

list::~list(){
while(removeF(d));
}





//node.h


#pragma once
#include "list.h"
class node
{
friend class list;
public:

private :
	node(int = 0,node = 0);  //error here  fatal error C1202: recursive type or function dependency context too complex
	~node(void);
	int data;
	node *ptr;
	
};



//node.cpp
#include "StdAfx.h"
#include "node.h"
#include "list.h"

node::node(int u, node * p)
{
	data = u;
	ptr = p;
}

node::~node(void)
{
}





thank you for your help

Is This A Good Question/Topic? 0
  • +

Replies To: Classes Help

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6066
  • View blog
  • Posts: 23,526
  • Joined: 23-August 08

Re: Classes Help

Posted 25 October 2009 - 11:04 AM

node(int = 0,node = 0);  //error

You're missing the variable name for the arguments.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1