Thread: Linked List header file

  1. #1
    Registered User
    Join Date
    Dec 2014
    Posts
    143

    Linked List header file

    This is my header file for a linked list class. When I try to compile it says an internal error has occurred. What is wrong with my code.

    Code:
    #pragma once
    
    
    #ifndef LINKED_LIST
    #define LINKED_LIST
    
    
    #include <iostream>
    #include <vector>
    
    
    #define LINKS 1
    
    
    template <class T> struct SingleLinkedNode;
    template <class T> struct DoubleLinkedNode;
    
    
    #if !defined(LINKS) || LINKS == 1
    template <class T, class U = SingleLinkedNode<T>>
    class LinkedList {
    #elif LINKS == 2
    template <class T, class U = DoubleLinkedNode<T>>
    class LinkedList {
    #else 
    #error implement me
    #endif // LINKS
    
    
    public:
    	struct SingleLinkedNode {
    		SingleLinkedNode *next = nullptr;
    		T data;
    	};
    
    
    	struct DoubleLinkedNode {
    		DoubleLinkedNode *previous = nullptr;
    		DoubleLinkedNode *next = nullptr;
    		T data;
    	};
    
    
    #ifndef NODE
    #define NODE
    #if !defined(LINKS) || LINKS == 1
    	struct Node : public SingleLinkedNode;
    #elif LINKS == 2
    	struct Node : public DoubleLinkedNode;
    #else 
    #error implement me
    #endif // LINKS
    #endif // NODE
    
    
    	LinkedList();
    	LinkedList(U *firstPtr);
    	LinkedList(T *ptr, const size_t& elements = 1);
    	LinkedList(const std::vector<T>& vectorRef);
    	template <size_t N> LinkedList(T arrayPtr[N]);
    	LinkedList(const LinkedList<T>& listRef);
    
    
    	~LinkedList();
    
    
    	U* first();
    	U* last();
    	U* at(const size_t& index);
    	U* del(const size_t& index);
    
    
    	void clear();
    	void set(U *firstPtr);
    	void set(T *ptr, const size_t& elements);
    	void set(const std::vector<T>& vectorRef);
    	template <size_t N> void set(T arrayPtr[N]);
    	void set(LinkedList<T> list);
    	void replace(const T& oldValue, const T& newValue);
    	void remove(const T& value);
    	void reverse();
    	void insertFront(const T& value);
    	void insertBack(const T& value);
    	void insert(const size_t& index, const T& value);
    	int countOf(const T& value);
    	bool contains(const T& value);
    	bool isEmpty();
    
    
    	T* data();
    	std::vector<T> data();
    	size_t length();
    	size_t size();
    
    
    	bool operator == (LinkedList<T> list);
    	LinkedList& operator = (LinkedList<T> list);
    	T& operator [] (const size_t& index);
    
    
    private:
    	U *firstNode;
    };
    
    
    #endif // LINKED_LIST

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,661
    Well posting your actual error message, rather than "an error" would be so much more informative.

    > template <class T, class U = SingleLinkedNode<T>>
    Also, you might find adding a space between the two closing >> works wonders for the parser.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    I could not replicate your problem, but my compiler (g++ 4.8.2) did report:
    Code:
    test.cpp:44:42: error: expected ‘{’ before ‘;’ token
         struct Node : public SingleLinkedNode;
                                              ^
    test.cpp:88:20: error: ‘std::vector<T> LinkedList<T, U>::data()’ cannot be overloaded
         std::vector<T> data();
                        ^
    test.cpp:87:8: error: with ‘T* LinkedList<T, U>::data()’
         T* data();
            ^
    EDIT:
    Quote Originally Posted by Salem
    Also, you might find adding a space between the two closing >> works wonders for the parser.
    Not likely since nullptr was used, so compiling with respect to C++11 or later should be expected.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  4. #4
    Registered User
    Join Date
    Dec 2014
    Posts
    143
    Error 1 error C1001: An internal error has occurred in the compiler.

    That's my error

  5. #5
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    What is the source file -- that included this header -- that you tried to compile?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  6. #6
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    Quote Originally Posted by cmajor28 View Post
    Error 1 error C1001: An internal error has occurred in the compiler.

    That's my error
    Are there compiler flags you can use to get more verbose output than that?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 6
    Last Post: 06-27-2014, 10:24 AM
  2. Replies: 10
    Last Post: 04-19-2012, 10:46 AM
  3. Linked list from file
    By kapil1089thekin in forum C++ Programming
    Replies: 2
    Last Post: 07-27-2010, 12:23 PM
  4. Circular doubly linked list with dummy header
    By mag_chan in forum C Programming
    Replies: 5
    Last Post: 10-31-2005, 08:44 AM
  5. file into a linked list
    By pilecom in forum C Programming
    Replies: 2
    Last Post: 10-17-2002, 12:14 AM