mardi 6 décembre 2022

warning: friend declaration 'void traverse(List

i have a Node template class in one "Node.cpp" and included in file "List.cpp" and List template class i have to create a traverse function which is friend to the List class to traverse all the node in a List but facing an error here is my error proner

List Class Decleration

template<typename T>
class List{
    private:
        Node<T> *headNode;
        Node<T> *currentNode;
        Node<T> *lastCurrentNode;
        int size;
    public:
        List();
        void add(T);
        T get();
        bool next();
        friend void traverse(List<T>); // **there is an issue**
};

Friend function Intialization

template <typename T>
void traverse(List <T>list)
{
    Node<T> *savedCurrentNode = new Node<T>();
    list.currentNode = list.headNode;

    for(int i=1; list.next(); i++)
    {
        cout << "\n Element " << i << " " << list.get();
    }
    list.currentNode = savedCurrentNode;
}

i am a bigner and try to implement using templates but stuck into a problem now i have no idea how to solve this

Aucun commentaire:

Enregistrer un commentaire