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 8552747
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:29:39+00:00 2026-06-11T14:29:39+00:00

We were taught how to overload cout the other day for our program to

  • 0

We were taught how to overload cout the other day for our program to cout but I don’t know how to make it output everything.

 template <NODETYPE>
 friend ostream &operator <<(ostream &, List<NODETYPE>& );


template<typename NODETYPE>
ostream &operator <<(ostream& output, List<NODETYPE>& value)
{ 
    output << value;
    return output;
}

However, my program has at least 5 objects to output and two of them are doubles. I get an error for that that says ‘double is not a valid type for a template constant parameter’

My two problems are: How do I output all my objects and not just the first object; and how do I get the double to output. Please and thanks!

EDIT: HUGE EDIT:::

Okay, I realized I was doing something wrong, rearranged my header, and source files.

And then I also realized that missing my lecturer’s class was one of the biggest mistakes I’ve ever made. My next error, was giving you all my assumptions, and not the information that I assumed from.

In my assignment, it says: • Write an assignment operator and a friend function to output the linked list.

in almost every other line of my main function(a function that I’m not allowed to alter), there is a cout:

List<int> Li, Li2, Li3;
List<double> Ld, Ld2;

These are my objects. And all my couts look something like this:

  cout << "Ld is: " << Ld << endl;

After rearranging my header and source files, I got this error:
“no match for ‘operator<<‘ in ‘std::operator<<[with_Traits = std::char_traits] (((std::basic_ostream>&)(& std::cout)), ((const char*) ‘Ld is”))<

I get that for every single cout statement I have. It’s more information than Ld exit status is 1 or whatever, so I’m going from this.

I’m still not fully keen on using this ostream overload function, so any help appreciated and thank you so much for your time!

EDIT::–

I’ve put almost all my code in this post: collect2: Ld returned 1 exit status build make error

If someone could help me with the overload that’d be great, because I think it’s the only problem I’ve got left so I can figure out everything else.

Thanks!!

  • 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-11T14:29:40+00:00Added an answer on June 11, 2026 at 2:29 pm

    You need to perform some kind of iteration over the List<NODETYPE>, printing out each node. Otherwise you have an infinite recursion, with the operator calling itself.

    This example prints out the elements separated by a single space, in a single line. I have omitted the details of the iteration mechanism because I don’t know your List interface.

    template<typename NODETYPE>
    ostream &operator <<(ostream& output, const List<NODETYPE>& value)
    { 
       for ( node in value) // pseudocode iteration
       {
         output << node << " ";
       }
       return output;
    }
    

    This assumes there is an ostream& operator<< for the node types, if not you have to provide that too. Also, note I pass the list by const reference. This has many advantages, one of them being you can pass temporary objects.

    Concerning the friend declaration, you also need template<typename T> there, but it isn’t clear you need the operator to be friend in the first place. Lists typically provide access to their elements in their public interface.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've taught myself Obj-C, and have been self-teaching Cocoa, but adding Core Data to
What I was taught at school is all about programming languages, software design, but
Or are we all sticking to our taught &&, ||, ! way? Any thoughts
I taught i had a clear view of the difference between these, but giving
In school we've been taught that compilers compile a computer program to machine language.
Sorry I'm only self taught but having trouble with something. I currently have a
After being taught how to create a hash table in class, I don't understand
I'm a self-taught beginning programmer. I've designed a horse racing program that reads in
We are always taught to make sure we use a break in switch statements
We are being taught xv6 in our course. Currently we use to login to

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.