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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T00:07:26+00:00 2026-05-25T00:07:26+00:00

Is nesting overloaded operators possible ? I would like to nest << inside a

  • 0

Is nesting overloaded operators possible ? I would like to nest << inside a ()

template<class T>
struct UnknownName
{
   T g;
   T&operator<<(std::ostream&os, const T&v){return os<<v;}
   bool operator()(const T&v)
   {
      if(v==g)
        //do the streaming << then return true
      else return false;
   }
};

Would you please help me out ? I am afraid my example is unreal enough to you, please just ask if you still have any doubts. Sincerely.

  • 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-05-25T00:07:26+00:00Added an answer on May 25, 2026 at 12:07 am

    The best I can think of would be to have operator<< return a specific type, and then overload operator() to accept that type:

    #include <cstdio>
    
    namespace {
        struct Foo {
            struct Bar {
                int i;
            };
    
            Foo& operator()(const Bar& b)
            {
                std::printf("bar, %d\n", b.i);
                return *this;
            }
    
            // obviously you don't *have* to overload operator()
            // to accept multiple types; I only did so to show that it's possible
            Foo& operator()(const Foo& f)
            {
                std::printf("foo\n");
                return *this;
            }
        };
    
        Foo::Bar operator<<(const Foo& f, const Foo& g)
        {
            Foo::Bar b = { 5 };
            return b;
        }
    }
    
    int main()
    {
        Foo f, g, h;
        f(g << h);
        f(g);
    }
    

    This isn’t a common idiom, to say the least.

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

Sidebar

Related Questions

Is the nesting of functions possible in the object oriented languages like C#, Java,
Does VB.NET have any scope nesting operators like {} in C type languages? Example
When I read about nesting an interface inside of a class, the intention appears
I'd like two different HTML elements that are at the same nesting level to
It seems that (strict) html doesn't allow nesting any non-inline elements inside a <p>
Is nesting of EL Expressions in Ternary Operator allowed? What is wrong with the
Quick question: is this kind of nesting possible? An if statement first passing a
I am nesting try catches inside of a main try catch statement, what I
I'd like to have variable defined in the nesting function to be altered in
I'm having trouble nesting my routes. It would probably be easiest to show you

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.