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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T02:55:04+00:00 2026-06-14T02:55:04+00:00

I have a question about a situation I just came upon at work. setup:

  • 0

I have a question about a situation I just came upon at work.

setup:
in stringStuff.h

namespace n1
{
namespace n2
{
    typedef std::string myString;
}
}

namespace n1
{
namespace n2
{
    void LTrim(myString& io_string);
    void RTrim(myString& io_string);

    inline void Trim(myString& io_string)
    {
        LTrim(io_string);
        RTrim(io_string);
    }
}
}

in impl.cpp

#include "stringStuff.h" // This actually gets included via other include files
#include "globalInclude.h" // contains 'using namespace n1::n2;'. Yes, I know this isn't best practice

inline static myString Trim(const myString& in_string)
{
    // impl
}

static void impl(const myString& in_string, myString& out_string)
{
    size_t N = 10; // just some computed value.
    out_string = Trim(in_string.substr(1, N)); // This is the line with the error
}

now, I admit I don’t understand C++ name resolution rules quite as well as I should, but when I look at this, it seems like the call to Trim should be ambiguous.

The surprising thing is that it compiles just fine on Linux using GCC, calling the function defined in impl.cpp. When I compile on HP-UX using its native compiler, it seems to resolve the call as the one defined in stringStuff.h, and complains about converting a temporary to a non-const ref (which is surprisingly a warning, not an error), and about trying to assign void to a myString.

What should be happening according to the C++ standard, and which compiler (if either) is getting it right?

BTW, I ‘fixed’ it in my case by prefixing the call to trim with ::, although that isn’t really ideal.

  • 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-14T02:55:05+00:00Added an answer on June 14, 2026 at 2:55 am

    The trick is that one takes a const reference and the other a non-const reference, so they are two different functions, not the same function whose resolution might be ambiguous. It then comes down to what the type of the parameter in the call is. Since substr returns a value, it can only bind to the const reference. So it should call ::Trim without a warning. I would say that the HP-UX compiler is wrong.

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

Sidebar

Related Questions

I have a question about getting DLL's directory on Windows system. The situation is
I have a question about jQuery load best practice. Imagine the following situation: $(#div).on('click',
I have already posted a question about this, but the situation has changed sufficiently
I still have a question about Enumerations. Here's a quick sketch of the situation.
I have a question about a situation I may find myself in. A database
I just have a question about putting a single form with multiple inputs into
I have question about parsing in Html helper : I have sth like: @foreach
I have question about clean thory in Python. When: @decorator_func def func(bla, alba): pass
I have question about XSLT1.0. The task is to write out in HTML all
I have question about normalization. Suppose I have an applications dealing with songs. First

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.