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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T08:21:08+00:00 2026-06-11T08:21:08+00:00

I have stumbled upon an error for which I cannot grasp the reason. I

  • 0

I have stumbled upon an error for which I cannot grasp the reason.

I think it basically gets down to this error:

 error: no matching function for call to ‘std::basic_ostream<char>::operator<<(const std::basic_string<char>&)’

I looked into specification on http://www.cplusplus.com and indeed it says there is no definition for std::ostream::operator<< with std::string as an argument.

My question is, what happens when one writes std_ostream_instance << std_fancy_string;. I believe it is one of the most common invocations ( e.g. std::out << std::string("Hello world!") ) next to const char*.

The error originates from these lines:

template<typename T> 
void Log::_log(const T& msg)
{  _sink->operator<<( msg ); }

_sink is defied as std::ostream*
There are some wrapping functions around but it breaks here.

I think I could work around by writing

template<> 
void Log::_log<std::string>(const std::string& msg) {
  _sink->operator<<( msg.c_str() );
}

since there is ostream& operator<< (ostream& out, const unsigned char* s ); defined by default.

I just see no reason why it is not guessed automatically since it clearly works in simple use like cout << any_std_string.

Not sure if this is relevant but I want to be able to pass down through my log functions anything than can be handled by std::ostream. I used explicit non-templated declarations but decided to move to template for log(const T& anything_to_log) to refacator it. It seemed plain stupid to have 5+ overloads. I get the error when I try compiling something like Log::log( std::string("test case") ).

It looks like something stupid-simple but I cannot get it on my own. Tried to google and search stack to no avail.

With regards, luk32.

PS. I checked the work-around and it works. Why it’s not implicitly done ?

  • 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-11T08:21:10+00:00Added an answer on June 11, 2026 at 8:21 am

    operator << overloads are not members of ostream. They are freestanding functions, for example

    ostream& operator << ( ostream& out, const basic_string<T>& bs );
    

    Try

    template<typename T> 
    void Log::_log(const T& msg)
    {  *_sink << msg;  }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm pretty new in iphone programming and have stumbled upon this issue which I
I'm quite new to hibernate and have stumbled on this problem, which I can't
I am currently experimenting with various input controls and have stumbled upon SneakyInput, which
I am debugging some old ASP code and have stumbled upon the following error:
I have stumbled upon a problem when calling a nested Async which happens to
Some of you might have stumbled upon this cute article - http://igoro.com/archive/quicksort-killer/ \ What
I have stumbled upon a situation where I cannot start more than a certain
I have stumbled upon a riddle which I can't explain, maybe someone here will
I am new to this Facebook coding game so have stumbled upon a fault
I have stumbled upon the following F77 yacc grammar: http://yaxx.cvs.sourceforge.net/viewvc/yaxx/yaxx/fortran/fortran.y?revision=1.3&view=markup . How can I

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.