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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T18:27:22+00:00 2026-06-07T18:27:22+00:00

Possible Duplicate: unresolved overloaded function type c++ Consider the code snippet below: #include <algorithm>

  • 0

Possible Duplicate:
unresolved overloaded function type c++

Consider the code snippet below:

#include <algorithm>
#include <cctype>
#include <string>
using namespace std;
void test(){
    std::string str = "Hello World!";
    std::transform(str.begin(), str.end(), str.begin(), tolower);
}

There is an error about tolower when compiling with G++: unresolved overloaded function.

If using namespace std; is removed, the code works fine.

Then, my questions are:

  • What is the relationship between namespace std with C functions?
  • What is the difference between #include<ctype.h> and #include<cctype>? Although both of them don’t work in the example above.
  • Why std::tolower also doesn’t work? What’s the difference between std::tolower and tolower?
  • 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-07T18:27:23+00:00Added an answer on June 7, 2026 at 6:27 pm

    There is no relationship between namespace std and C functions. But
    your code isn’t C, it’s C++, so you also have to consider C++ functions.
    Like std::tolower, for example, in <locale>. Your problem is due to
    a concurrence of things:

    • One of the headers you include includes <locale>. C++ headers are
      allowed to include other C++ headers, and which header includes which
      other header may vary from one implementation to the other, so the
      code you’ve written might compile with one compiler, and not with
      another.

    • You’re trying to pass the function as a pointer to function argument,
      to a function template where the argument is a template type
      parameter. Simply put, in order to do overload resolution on
      tolower here, the compiler must match it to the type of the
      argument, and in order to know the type of the argument, the compiler
      must do template type deduction based on the exact type of the
      function, which it can only know once it has done overload resolution.

    If you want the function in <ctype.h> (which you don’t, since it would
    result in undefined behavior), you can get it either by including
    <ctype.h> (which guarantees that it is present in the global
    namespace) and using ::tolower, or by explicitly specifying the
    overload you want, e.g. static_cast<int (*)(int)>( tolower ) (In this
    particular case, static_cast doesn’t mean type conversion, but
    explicit overload resolution.)

    In practice, of course, you don’t do this sort of thing. If you’re
    doing any text processing at all, you’ll define all of the necessary
    functions as functional object types, which avoid undefined behavior by
    either converting the input to unsigned char:

    struct ToLower
    {
        char operator()( char ch ) const
        {
            return ::tolower( static_cast<unsigned char>( ch ) );
        }
    };
    

    or by using the functions in <locale> which do work with char:

    class ToLower
    {
        std::locale myLocale;   //  necessary to guarantee the lifetime of the facet.
        std::ctype const* myCType;
    public:
        ToLower( std::locale const& loc = std::locale() )
            ; myLocal( loc )
            , myCType( &std::use_facet<std::ctype>( loc ) )
        {
        }
    
        bool operator()( char ch ) const
        {
            return myCType->tolower( ch );
        }
    };
    

    Finally, WRT your second question: the difference depends on the version
    of C++ you’re using and the compiler. Globally, however: <ctype.h>
    will introduce the functions into the global namespace; <cctype> will
    introduce them into the namespace std::, and maybe (or maybe not) into
    the global namespace. (And your third question has already been
    answered above: std::tolower refers to a set of overloaded functions
    defined in <locale> and <cctype>; ::tolower refers to a single
    function defined in <ctype.h>, and just tolower is the equivalent of
    ::tolower, unless you’ve done using namespace std, in which case,
    it will refer to the overload set of all of the functions mentionned
    above.

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

Sidebar

Related Questions

Possible Duplicate: How to get the address of an overloaded member function? I have
Possible Duplicate: Difference of create Index by using include column or not using Edit:
Possible Duplicate: An algorithm to "spacify" CamelCased strings I have a string like this:
Possible Duplicate: Why do I get “unresolved external symbol” errors when using templates? I
Possible Duplicate: How do I make a request using HTTP basic authentication with PHP
Possible Duplicate: && operator in Javascript In the sample code of the ExtJS web
Possible Duplicate: Can main function call itself in C++? I found this problem very
Possible Duplicate: Convert some code from C++ to C I've got some code that
Possible Duplicate: PHP get all arguments as array? Within a javascript function arguments always
Possible Duplicate: regex for URL including query string I have a text or message.

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.