10
template<typename Type> class SingleList;

template<typename Type> class ListNode{
private:
    friend typename SingleList<Type>;  
    //this line appears"expected a qualified name after 'typename'"

    ListNode():nextNode(NULL){}

    ListNode(const Type item,ListNode<Type> *next=NULL):nodeData(item),nextNode(next){}

    ~ListNode(){
        nextNode=NULL;
}

public:
        Type GetData();
        friend ostream& operator<< <Type>(ostream& ,ListNode<Type>&);

private:
        Type nodeData;
        ListNode *nextNode;
};

The code:

friend typename SingleList<Type>;  

expected a qualified name after 'typename' and how to solve it. Thank you.

egrunin
  • 24,650
  • 8
  • 50
  • 93
tonysok
  • 627
  • 1
  • 7
  • 13
  • Related: http://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords – RiaD Aug 01 '13 at 15:25

1 Answers1

9

You want

friend class SingleList<Type>;

typename can be used instead of class inside the template parameter declaration, but not everywhere.

Ben Voigt
  • 277,958
  • 43
  • 419
  • 720
  • `clang` just gave me OP's error, while both `MingW` and `MSVC` compile same source-code without issue. – Top-Master Dec 09 '22 at 10:32
  • Maybe there is a `clang` flag that needs to be added or removed, to make `clang` compatible with other compilers? – Top-Master Dec 09 '22 at 10:32