Compiler Issues

Started by
2 comments, last by Ted_Striker 18 years, 7 months ago
Ive got a bit of a compiler issue with some old code. The following code snippit was originaly written in visual studio 6.0, yesterday I tried compiling an old game I wrote ( as well as its tile editor) and got the following errors List.h(78): error C2143: syntax error : missing ';' before '*' LList.h(78): error C2501: 'LinkedListIterator<Type>::currentNode' : missing storage-class or type specifiers LList.h(78): warning C4346: 'LList<Type>::Node' : dependent name is not a type I ran it on my old machine running 6.0 yesterday and it worked. I also gave the code to a friend who is using the same .net compiler(we checked the version numbers) and it worked for him the only difference is he doesnt have the .Net SP1 installed. So could the .Net Service Pack be causing this problem? heres most of the code


//////////////////////////////////////////////////////////////////
// File: "LList.h"
//
// Purpose: A doubly linked templated list and iterator.
//
//////////////////////////////////////////////////////////////////

#if !defined(AFX_LLIST_H__1BE8D7C8_7710_45EC_A59E_99BAC77CDCA7__INCLUDED_)
#define AFX_LLIST_H__1BE8D7C8_7710_45EC_A59E_99BAC77CDCA7__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <windows.h>

// forward declaration to allow the LinkedList
// to know about LinkedListIterator.
template <typename Type> class LinkedListIterator;

template <typename Type>
class LList
{
// Protected so we can derive a stack or queue
protected:

	// create a friend class declaration
	// the iterator is a friend.
	friend class LinkedListIterator<Type>;

	// A Node structure. We store the templated data
	// and pointers to the next and previous nodes.
	struct Node
	{
		Node *next;
		Node *prev;

		Type Data;
	};

	// Head and tail pointers. These allow us quick access
	// to the beginning and end of the list.
	Node *head;
	Node *tail;

	// The number of nodes in the list
	int ListSize;

	// Internal functions used for insertion and deletion
	bool Delete(Node** node);
	bool Insert(Node *node, Type data);

public:

	// Constructor
	LList();

	// Destructor
	~LList();
};


/******************************/
/* Linked List Iterator Class */
/******************************/


// LinkedListIterator
// used to handle for-looping and accessing our list.
template <typename Type>
class LinkedListIterator
{
   private:

      // our iterator keeps track of the 'current'
      // element that it is looking at.
      LList<Type> *list;
      LList<Type>::Node *currentNode;

   public:

      // Ctr.
      // the constructor has to know which
      // list to work with.
      LinkedListIterator (LList<Type> *theList);

      // initialize the iterator to start at the beginning
      void setToHead () { currentNode = list->head; }
	  
	  // initialize the iterator to end 
	  void setToTail() { currentNode = list->tail; }

      // a function to check to see if we are finished.
      bool finished () { return (currentNode == NULL); }
	  
	  // check if were at the beginning
	  bool atStart() { return (currentNode == list->head->prev); }

      // a way to increment the iterator.
      LinkedListIterator<Type> &operator++ ();
	  
	  // decrement the iterator
	  LinkedListIterator<Type> &operator--();

      // get access to the current item
      Type current () { return currentNode->Data; }
};

// constructor
//IN: theList  the list to iterate
template <typename Type>
LinkedListIterator<Type>::LinkedListIterator (LList<Type> *theList)
{
   list = theList; // store the list.
   // initialize the currentNode.  
   currentNode = NULL;
}

// increment the iterator
template <typename Type>
LinkedListIterator<Type> &LinkedListIterator<Type>::operator++ ()
{
   if (currentNode != NULL) // currentNode already at end?
   {
      currentNode = currentNode->next;
   }
  
   return *this;
}

// decrement the iterator
template <typename Type>
LinkedListIterator<Type> &LinkedListIterator<Type>::operator--()
{	
	// same as ++ only move to the previous node
	if (currentNode != NULL)
	{
		currentNode = currentNode->prev;
	}

	return *this;
}

#endif // !defined(AFX_LLIST_H__1BE8D7C8_7710_45EC_A59E_99BAC77CDCA7__INCLUDED_)




Advertisement
I should also stat that im trying to recompile this under .net 2003 with the .net sp1 installed.

Im curious to here from people who have .net 2003 with or without the sp1

Ted
Did you upgrade compilers? (edit: looks like you did) Standard C++ requires that dependent types on template parameters scoped with the :: operator have the typename keyword attached. i.e.:

LList<Type>::Node *currentNode;

should be:

typename LList<Type>::Node *currentNode;


MSVC 6 does not require this as it is not standards compliant.
Hmm that worked dude, Ill have to remember that. Now I gotta find out why my friend said it compiled for him.

Thanks

This topic is closed to new replies.

Advertisement