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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T07:19:47+00:00 2026-06-15T07:19:47+00:00

I want to print all the arguments of function using variadic templates feature of

  • 0

I want to print all the arguments of function using variadic templates feature of C++11. And I did the following:

struct concatenate
{

    template< typename ...ARGS >
    explicit
    concatenate(ARGS const & ...args)
    {
        cat(args...);
    }

    /*explicit*/
    operator std::string const () const
    {
        return oss.str();
    }

private :

    std::ostringstream oss;

    void cat() const
    { ; }

    template< typename T, typename ...ARGS >
    void cat(T const & head, ARGS const & ...tail)
    {
        if (oss.tellp() > 0) {
            oss << ' ';
        }
        oss << head;
        cat(tail...);
    }

};

Then I try to test it:

std::cout << '\'' << concatenate(1, 2, 3, 4, std::string("ololo"), "alala", 'o', 1.2, 1.2L, 1.2f) << '\'' << std::endl;

but then given the code does not compile with error:

error: cannot bind 'std::basic_ostream<char>' lvalue to 'std::basic_ostream<char>&&'
c:\mingw\lib\gcc\mingw32\4.7.0\include\c++\ostream:600: error: initializing argument 1 of 'std::basic_ostream<_CharT, _Traits>& std::operator<<(std::basic_ostream<_CharT, _Traits>&&, const _Tp&) [with _CharT = char; _Traits = std::char_traits<char>; _Tp = concatenate]'

What is the nature of the error? After all, the compiler has no choice but to use a conversion operator. It isn’t?

  • 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-15T07:19:48+00:00Added an answer on June 15, 2026 at 7:19 am

    operator << for class template std::basic_string is defined as (free) function template. In contrast with non-template functions, template argument deduction doesn’t involve possible argument conversions. Templated operator << for basic_string needs exactly a string as it right argument and implicit conversion (from concatenate to string) doesn’t work.

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

Sidebar

Related Questions

I want to print an integer number in binary mode using following function: #include
I want to make a custom print function that takes any amount of arguments
I want to print all the prime numbers between two numbers. This is my
I want to print values of all the types like char, long... so on
I want to print some dynamic query to execute a procedure on all tables
I want to read a folder for all the files and programmatically print them
I have the following Sub: Public Function Log(sdsMessage As CStandardPropertySet2) ' Only print the
I am using buildr and I am trying to print all of my command
I want my function to return multiple dictionaries based on calling arguments. e.g. if
I Want Print DataBase Schema in Microsoft Sql Server Compact Edition. Maybe Exist Some

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.