I can't work around these errors. Can someone help me out?

Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
Error 3 error C2238: unexpected token(s) preceding ';'
Error 1 error C2143: syntax error : missing ';' before '<'

Code:

#pragma once
    #ifndef RainfallList_H
    #define RainfallList_H

    #include "Rainfall.h"
    #include <iostream>

    using namespace std;

    //*********************************************
    // LinkedList class                           *
    //*********************************************
    template <class L>
    class RainfallList:Rainfall
    {

    public:
        RainfallList()
        {
            head = NULL; // Establishes empty linked list
        }

        ~RainfallList();
        // Linked list operations
        void appendNode(L);
        void insertNode(L);
        void deleteNode(L);
        void displayList() const;

    private:
        RainfallListNode<L> *head;   // List head pointer
    };

    //*********************************************
    // The ListNode class creates a type used to  *
    // store a node of the linked list.           *
    //*********************************************
    template <class L>
    class RainfallListNode
    {
    public:
        L value;           // Node value
        RainfallListNode<L> *next; // Pointer to the next node

        // Constructor
        RainfallListNode(L nodeValue)
        {
            value = nodeValue;
            next = NULL;
        }
    };

    //***********************************************
    // appendNode function adds the node to the end *
    // list. It accepts an argument. *
    //***********************************************
    template <class L>
    void RainfallList<L>::appendNode(L num)
    {
        List *newNode; // To point to a new node
        List *nodePtr; // To move through the list 

        // Allocate a new node and store num there
        newNode = new List;
        newNode->value = num;
        newNode->next = NULL;

        // If there are no nodes in the list make
        // newNode the first node
        if (!head)
        {
            head = newNode;
        }
        else // Otherwise, insert newNode at end
        {
            // Intialize nodePtr to head of list
            nodePtr = head;

            // Find the last node in the list
            while (nodePtr->next)
            {
                nodePtr = nodePtr->next;
            }

            // Insert newNode as the last node
            nodePtr->next = newNode;
        }
    }

    //***********************************************
    // insertNode function inserts the node in *
    // numerical order. It accepts an argument. *
    //***********************************************
    template <class L>
    void RainfallList<L>::insertNode(L num)
    {
        List *newNode; // A new node
        List *nodePtr; // To traverse the list
        List *previousNode = NULL; // The previous node 

        // Allocate a new node and store num there
        newNode = new List;
        newNode->value = num;

        // If there are no nodes in the list make
        // newNode the first node
        if (!head)
        {
            head = newNode;
            newNode->next = NULL;
        }
        else // Otherwise, insert newNode
        {
            // Position nodePtr at the head of list
            nodePtr = head;

            // Initialize previousNode to NULL
            previousNode = NULL;

            // Skip all nodes whose value is less than num
            while (nodePtr != NULL && nodePtr->value < num)
            {
                previousNode = nodePtr;
                nodePtr = nodePtr->next;
            }

            // If the new node is to be the 1st in the list
            // insert it before all other nodes
            if (previousNode == NULL)
            {
                head = newNode;
                newNode->next = nodePtr;
            }
            else // Otherwise insert after the previous node
            {
                previousNode->next = newNode;
                newNode->next = nodePtr;
            }
        }
    }


    //***********************************************
    // deleteNode function removes the node from the*
    // list without breaking the links created by *
    // the next pointers and removes the node from *
    // memory. *
    //***********************************************
    template <class L>
    void RainfallList<L>::deleteNode(L num)
    {
        List *nodePtr; // To traverse the list
        List *previousNode; // To point to the previous node 

        // If the list is empty, do nothing
        if (!head)
        {
            return;
        }

        // Determine if the first node is the one
        if (head->value == num)
        {
            nodePtr = head->next;
            delete head;
            head = nodePtr;
        }
        else
        {
            // Intialize nodePtr to head of list
            nodePtr = head;

            // Skip all nodes whose value member is not
            // equal to num
            while (nodePtr != NULL && nodePtr->value != num)
            {
                previousNode = nodePtr;
                nodePtr = nodePtr->next;
            }

            // If nodePtr is not at the end of the list, link
            // the previous node to the node after nodePtr,
            // the delete nodePtr
            if (nodePtr)
            {
                previousNode->next = nodePtr->next;
                delete nodePtr;
            }
        }
    }

    //***********************************************
    // displayList shows the value stored in each *
    // node of the linked list pointed to by head *
    //***********************************************
    template <class L>
    void RainfallList<L>::displayList() const
    {
        List *nodePtr; // To move through the list 

        // Postion nodePtr at the head of the list
        nodePtr = head;

        // While nodePtr points to a node, traverse the list
        while (nodePtr)
        {
            // Display the value in this node
            cout << nodePtr->value << " ";

            // Move to the next node
            nodePtr = nodePtr->next;
        }
    }

    //***********************************************
    // Destructor function deletes every node in the*
    // list. *
    //***********************************************
    template <class L>
    RainfallList<L>::~RainfallList()
    {
        List *nodePtr; // To traverse the list
        List *nextNode; // To point to the next node 

        // Position nodePtr at the head of the list
        nodePtr = head;

        // While nodePtr is not at the end of the list
        while (nodePtr != NULL)
        {
            // Save a pointer to the next node
            nextNode = nodePtr->next;

            // Delete the current node
            delete nodePtr;

            // Position nodePtr at the next node
            nodePtr = nextNode;
        }
    }
    #endif

The first error is that you have a single collon (:) and then the word Rainful [line 14]. After that without Rainfall.h is would take me too much time to guess what you are doing. So please post that file.

My guess -- define RainfallListNode before RainfallList because RainfallList uses RainfallListNode which has not been declared yet.

Okay so I managed to switched things around and edit a f ew lines and it works!

But now Im adding the functions for getLargest and getSmallest from my list.
But now Im getting a bunch of errors

Error 1 error C2440: 'initializing' : cannot convert from 'int' to 'Rainfall'
Error 4 error C2275: 'L' : illegal use of this type as an expression
Error 8 error C2227: left of '->value' must point to class/struct/union/generic type
Error 3 error C2065: 'RainfallListNode' : undeclared identifier
Error 5 error C2065: 'nodePtr' : undeclared identifier

etc...for pretty much everyy line within the getLargest and getSmallest head
Code:

#pragma once
#ifndef RainfallList_H
#define RainfallList_H

#include "Rainfall.h"
#include <iostream>

using namespace std;


//*********************************************
// LinkedList class                           *
//*********************************************
template <class L>
class RainfallList
{

public:
    RainfallList()
    {
        head = NULL; // Establishes empty linked list
    }

    ~RainfallList();
    // Linked list operations
    void appendNode(L);
    void insertNode(L);
    void deleteNode(L);
    void displayList() const;
    Rainfall getLargest();
    Rainfall getSmallest();

private:
    struct ListNode
    {
        L value;                    // The value in this node
        struct ListNode *next;      // To point to the next node 
    };

    ListNode *head;   // List head pointer
};


//***********************************************
// appendNode function adds the node to the end *
// list. It accepts an argument. *
//***********************************************
template <class L>
void RainfallList<L>::appendNode(L num)
{
    ListNode *newNode; // To point to a new node
    ListNode *nodePtr; // To move through the list 

    // Allocate a new node and store num there
    newNode = new ListNode;
    newNode->value = num;
    newNode->next = NULL;

    // If there are no nodes in the list make
    // newNode the first node
    if (!head)
    {
        head = newNode;
    }
    else // Otherwise, insert newNode at end
    {
        // Intialize nodePtr to head of list
        nodePtr = head;

        // Find the last node in the list
        while (nodePtr->next)
        {
            nodePtr = nodePtr->next;
        }

        // Insert newNode as the last node
        nodePtr->next = newNode;
    }
}

//***********************************************
// insertNode function inserts the node in *
// numerical order. It accepts an argument. *
//***********************************************
template <class L>
void RainfallList<L>::insertNode(L num)
{
    ListNode *newNode; // A new node
    ListNode *nodePtr; // To traverse the list
    ListNode *previousNode = NULL; // The previous node 

    // Allocate a new node and store num there
    newNode = new List;
    newNode->value = num;

    // If there are no nodes in the list make
    // newNode the first node
    if (!head)
    {
        head = newNode;
        newNode->next = NULL;
    }
    else // Otherwise, insert newNode
    {
        // Position nodePtr at the head of list
        nodePtr = head;

        // Initialize previousNode to NULL
        previousNode = NULL;

        // Skip all nodes whose value is less than num
        while (nodePtr != NULL && nodePtr->value < num)
        {
            previousNode = nodePtr;
            nodePtr = nodePtr->next;
        }

        // If the new node is to be the 1st in the list
        // insert it before all other nodes
        if (previousNode == NULL)
        {
            head = newNode;
            newNode->next = nodePtr;
        }
        else // Otherwise insert after the previous node
        {
            previousNode->next = newNode;
            newNode->next = nodePtr;
        }
    }
}


//***********************************************
// deleteNode function removes the node from the*
// list without breaking the links created by *
// the next pointers and removes the node from *
// memory. *
//***********************************************
template <class L>
void RainfallList<L>::deleteNode(L num)
{
    ListNode *nodePtr; // To traverse the list
    ListNode *previousNode; // To point to the previous node 

    // If the list is empty, do nothing
    if (!head)
    {
        return;
    }

    // Determine if the first node is the one
    if (head->value == num)
    {
        nodePtr = head->next;
        delete head;
        head = nodePtr;
    }
    else
    {
        // Intialize nodePtr to head of list
        nodePtr = head;

        // Skip all nodes whose value member is not
        // equal to num
        while (nodePtr != NULL && nodePtr->value != num)
        {
            previousNode = nodePtr;
            nodePtr = nodePtr->next;
        }

        // If nodePtr is not at the end of the list, link
        // the previous node to the node after nodePtr,
        // the delete nodePtr
        if (nodePtr)
        {
            previousNode->next = nodePtr->next;
            delete nodePtr;
        }
    }
}

//***********************************************
// displayList shows the value stored in each *
// node of the linked list pointed to by head *
//***********************************************
template <class L>
void RainfallList<L>::displayList() const
{
    ListNode *nodePtr; // To move through the list 

    // Postion nodePtr at the head of the list
    nodePtr = head;

    // While nodePtr points to a node, traverse the list
    while (nodePtr)
    {
        // Display the value in this node
        cout << nodePtr->value << " ";

        // Move to the next node
        nodePtr = nodePtr->next;
    }
}

//***********************************************
// Destructor function deletes every node in the*
// list. *
//***********************************************
template <class L>
RainfallList<L>::~RainfallList()
{
    ListNode *nodePtr; // To traverse the list
    ListNode *nextNode; // To point to the next node 

    // Position nodePtr at the head of the list
    nodePtr = head;

    // While nodePtr is not at the end of the list
    while (nodePtr != NULL)
    {
        // Save a pointer to the next node
        nextNode = nodePtr->next;

        // Delete the current node
        delete nodePtr;

        // Position nodePtr at the next node
        nodePtr = nextNode;
    }
}

template <class L>
Rainfall RainfallList<L>::getLargest()
{
    Rainfall obj = NULL;
    Rainfall obj2 = NULL;

    RainfallListNode<L> *nodePtr;  // To move through the list

    // Position nodePtr at the head of the list.
    nodePtr = head;

    obj = nodePtr->value;

    // While nodePtr points to a node, traverse
    // the list.
    while (nodePtr)
    {
        // Display the value in this node.
        //cout << nodePtr->value << endl;
        obj2 = nodePtr->value;

        if (obj.getRainfall() < obj2.getRainfall()){
            obj = nodePtr->value;
        }

        // Move to the next node.
        nodePtr = nodePtr->next;
    }

    return obj;
}

template <class L>
Rainfall RainfallList<L>::getSmallest()
{
    Rainfall obj = NULL;
    Rainfall obj2 = NULL;

    RainfallListNode<L> *nodePtr;  // To move through the list

    // Position nodePtr at the head of the list.
    nodePtr = head;

    obj = nodePtr->value;

    // While nodePtr points to a node, traverse
    // the list.
    while (nodePtr)
    {
        // Display the value in this node.
        //cout << nodePtr->value << endl;
        obj2 = nodePtr->value;

        if (obj.getRainfall() > obj2.getRainfall()){
            obj = nodePtr->value;
        }

        // Move to the next node.
        nodePtr = nodePtr->next;
    }

    return obj;
}

#endif

If you want the implementation code in the header file then you have to make them inline methods of the class, not coded outside the class as you would in *.cpp file. The implementation code cannot usually be separate from the template class declaration because the type can be different for each instance of the template. For example:

emplate <class L>
class RainfallList
{

public:
    RainfallList()
    {
        head = NULL; // Establishes empty linked list
    }

    ~RainfallList();
    // Linked list operations
    void appendNode(L)
    {
        ListNode *newNode; // To point to a new node
        ListNode *nodePtr; // To move through the list 

        // Allocate a new node and store num there
        newNode = new ListNode;
        newNode->value = num;
        newNode->next = NULL;

        // If there are no nodes in the list make
        // newNode the first node
        if (!head)
        {
            head = newNode;
        }
        else // Otherwise, insert newNode at end
        {
            // Intialize nodePtr to head of list
            nodePtr = head;

            // Find the last node in the list
            while (nodePtr->next)
            {
                nodePtr = nodePtr->next;
            }

            // Insert newNode as the last node
            nodePtr->next = newNode;
        }
}       
    void insertNode(L);
    void deleteNode(L);
    void displayList() const;
    Rainfall getLargest();
    Rainfall getSmallest();

private:
    struct ListNode
    {
        L value;                    // The value in this node
        struct ListNode *next;      // To point to the next node 
    };

    ListNode *head;   // List head pointer
};

Edited 2 Years Ago by Ancient Dragon

This article has been dead for over six months. Start a new discussion instead.