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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T10:32:48+00:00 2026-05-20T10:32:48+00:00

When I try to use a ternary conditional operator (?:) with stream buffer redirection,

  • 0

When I try to use a ternary conditional operator (?:) with stream buffer redirection, gcc produces ‘synthesized method first required here’ error. What is the problem, and how to correct the following program?

#include <fstream>
#include <iostream>

int main(int argc, char* argv[])
{
    using namespace std;
    cout << cin.rdbuf();    //OK
    ofstream("tmp.txt") << cin.rdbuf(); //OK

    int i=1;
    (i > 1 ? ofstream("tmp.txt") : cout) << cin.rdbuf(); //Compilation ERROR. Why?
    return 0;
}

compiled with gcc4.4:

...    
/usr/include/c++/4.4/bits/ios_base.h: In copy constructor ‘std::basic_ios<char,   std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)’:  
/usr/include/c++/4.4/bits/ios_base.h:790: error: ‘std::ios_base::ios_base(const std::ios_base&)’ is private  
/usr/include/c++/4.4/iosfwd:47: error: within this context  
/usr/include/c++/4.4/iosfwd: In copy constructor ‘std::basic_ostream<char,   std::char_traits<char> >::basic_ostream(const std::basic_ostream<char,   std::char_traits<char> >&)’:  
/usr/include/c++/4.4/iosfwd:56: note: **synthesized method** ‘std::basic_ios<char,   std::char_traits<char> >::basic_ios(const std::basic_ios<char, std::char_traits<char> >&)’   **first required here**   
../item1_1.cpp: In function ‘int main(int, char**)’:  
../item1_1.cpp:12: note: synthesized method ‘std::basic_ostream<char,   std::char_traits<char> >::basic_ostream(const std::basic_ostream<char,   std::char_traits<char> >&)’ first required here   
  • 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-20T10:32:49+00:00Added an answer on May 20, 2026 at 10:32 am

    This compiled OK with my version of clang, I think that it may be a gcc bug.

    From my reading of the standard, cout is an lvalue of type std::ostream and ofstream("tmp.txt") is an rvalue of type std::ofstream.

    Neither has any cv-qualifiers and std::ostream is a base class of std::ofstream so the conditional operator is valid an the result is an rvalue and has type std::ostream.

    There is no copying of either operand implied.

    if E1 and E2 have class type, and the underlying class types are the same or one is a base class of the other: E1 can be converted to match E2 if the class of T2 is the same type as, or a base class of, the class of T1, and the cv-qualification of T2 is the same cv-qualification as, or a greater cv-qualification than, the cv-qualification of T1. If the conversion is applied, E1 is changed to an rvalue of type T2 that still refers to the original source class object (or the appropriate subobject thereof). [Note: that is, no copy is made. ]

    The operator<< overload that you are using is a member of std::ostream so there is no need to bind a temporary to a non-const reference, the member can be called on a non-const rvalue.

    basic_ostream<charT,traits>&
        basic_ostream<charT,traits>::operator<< (basic_streambuf<charT,traits>* sb);
    

    Edit

    Note that this has changed in C++0x. Now, if the result of a conditional expression is an rvalue a temporary copy is always made. As objects of type ostream are not copyable your code will not be valid in C++0x.

    See here: http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_defects.html#446

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

Sidebar

Related Questions

i try to use TBXML and getting this error TBXML class method +tbXMLWithURL not
When I'm taking my query using Ajax on jQuery, o try use the method
I try use string as a regular expression pattern but I've following errors PHP
I try use a integer array in java with the code below: public static
I try to use a variable in my kshell script but can't get a
I try to use the great particle emitter which Michael Daley build for his
I try to use SQL SERVER VIEW within RIA Services. So I created some
i try to use jquery .text() but not really work : Before <a id=group_name
I try to use this: xml2struct when I use this xml: <XMLname attrib1=Some value>
I try to use the columnFilter add-on of jquery datatable but I couldn't make

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.