Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7995085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:18:22+00:00 2026-06-04T14:18:22+00:00

The g++ compiler prompt the following statement is wrong: template<typename Type> class SingleList{ public:

  • 0

The g++ compiler prompt the following statement is wrong:

template<typename Type>
class SingleList{
public:
    SingleList()
        {
            head =  new SingleListNode<Type> () ;    //Error happens here!!!
        }

The error message is :

 ./inc/single_list.h: In instantiation of ‘SingleListNode<int>’:
./inc/single_list.h|39 col 13| instantiated from ‘SingleList<Type>::SingleList() [with Type = int]’

The definition of head is the following, maybe problem is not related here.

SingleListNode<Type> *head;

The instantiation of class SingleList in main function is :

int main()
{
    SingleList<int> list;

I don’t know where the syntax error happens, can anyone help me? Thanks!!

========================================================================

The following is the content of source file:

    template<typename Type> class SingleList;

template<typename Type> class SingleListNode{
private:
    friend class SingleList<Type>;

    SingleListNode() : next(NULL){}

public:
    friend ostream& operator<< <Type>(ostream& os,SingleListNode<Type>& sln);             //Error here!!

private:
    SingleListNode *next;
};

template<typename Type> ostream& operator<<(ostream& os,SingleListNode<Type>& out){
    os<<out.data;
    return os;
}

template<typename Type> class SingleList{
public:
    SingleList()
        {
            head =  new SingleListNode<Type> () ;              //Error happens here.
        }
    ~SingleList(){
        delete head;                                       //Same error
    }

private:
    SingleListNode<Type> *head;
};

The error message prompted by g++

|| g++ -g -I ./inc/ -c single_list_test.cpp  -o single_list_test.o
|| single_list.h: In instantiation of ‘SingleListNode<int>’:
single_list.h|25 col 13| instantiated from ‘SingleList<Type>::SingleList() [with Type = int]’
single_list_test.cpp|9 col 18| instantiated from here
single_list.h|10 col 18| error: template-id ‘operator<< <int>’ for ‘std::ostream& operator<<(std::ostream&, SingleListNode<int>&)’ does not match any template declaration
|| make: *** [single_list_test.o] Error 1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:18:24+00:00Added an answer on June 4, 2026 at 2:18 pm

    To my gcc , just modify the following statement

    friend ostream& operator<< <Type>(ostream& os,SingleListNode<Type>& sln)
    

    to

     friend ostream& operator<< (ostream& os,SingleListNode<Type>& sln)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

g++ compiler gives this error: expected `;' before 'it' template <typename T> class myList
The compiler (VC8) error is: error C2680: 'std::_Tree<_Traits>::iterator' : invalid target type for dynamic_cast
The compiler doesn't know where stat.h is? Error: c:\Projects\ADC_HCI\mongoose.c(745) : error C2079: 'st' uses
The compiler complains about this code: HashMap<String,int> userName2ind = new HashMap<String,int>(); for (int i=0;
The compiler, given the following code, tells me Use of unassigned local variable 'x'.
If I need to use microsoft C# compiler from the normal command prompt, it
I'm writing a Generic class as follows. public class Foo<T> : where T :
As soon as I open the VS cmd prompt it says ERROR: Cannot determine
When attempting to compile my C# project, I get the following error: 'C:\Documents and
I want to compile C code from the Command Prompt in Windows. I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.