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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:53:03+00:00 2026-06-10T22:53:03+00:00

I am creating a custom ostream class which is briefly exposed in the following

  • 0

I am creating a custom ostream class which is briefly exposed in the following snippet. I would like to be able to use std::endl but the compiler does not let me. I don’t understand why.

#include <iostream> 

struct Bar
{
};

template <typename T>
struct Foo
{
};

template <typename T, typename U>
Foo<T>& operator<<(Foo<T>& _foo, U&&)
{
  return _foo;
}

int main()
{
  Foo<Bar> f;
  f << "aa" << std::endl;
}

The error gcc 4.7.1 gives me is:

main.cpp:21:21: error: no match for ‘operator<<’ in ‘operator<< ((* & f), (*”aa”)) << std::endl’ main.cpp:21:21:
note: candidates are: main.cpp:13:9: note: template
Foo& operator<<(Foo&, U&&) main.cpp:13:9: note: template
argument deduction/substitution failed: main.cpp:21:21: note:
couldn’t deduce template parameter ‘U’

Why can’t it deduce parameter U? Shouldn’t this be typeof(std::endl) ?

  • 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-10T22:53:04+00:00Added an answer on June 10, 2026 at 10:53 pm

    Since std::endl is

    namespace std {
    template <class charT, class traits>
    basic_ostream<charT,traits>& endl(basic_ostream<charT,traits>& os);
    }
    

    Your class is not derived from basic_ostream, so it cannot work.

    And basic_ostream has

    basic_ostream<charT,traits>& operator<<
    (basic_ostream<charT,traits>& (*pf)(basic_ostream<charT,traits>&))
    

    for works with manipulators like std::endl.

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

Sidebar

Related Questions

I am looking into creating custom keyboard for Android, but I would like to
I use PopupWindow class for creating custom popup window. But when I add layout_margin
When I'm creating custom classes, I'd like to be able to skip the alloc
I'm creating custom forum software for a site I'm building, which includes 2 tables
I need to implement creating custom gesture(like Gesture Builder in Android ) in my
So I followed the following tutorial on creating custom views associated with device orientations:
while creating custom item renderers which interfaces we need to implement? Thank in advance.
I am creating custom code snippet templates using DevExpress' CodeRush. Is there anyway for
I am creating custom email validation attribute, my code : public class EmailAttribute :
I am creating a Custom dialog where I want to use both DatePicker and

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.