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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T23:20:51+00:00 2026-05-10T23:20:51+00:00

Is their a way to use a non-member non-friend function on an object using

  • 0

Is their a way to use a non-member non-friend function on an object using the same ‘dot’ notation as member functions?

Can I pull a (any) member out of a class, and have users use it in the same way they always have?

Longer Explanation:

Scott Meyers, Herb Sutter, et all, argue that non-member non-friend functions are a part of an object’s interface, and can improve encapsulation. I agree with them.

However, after recently reading this article: http://www.gotw.ca/gotw/084.htm I find myself questioning the syntax implications.

In that article, Herb proposes having a single insert, erase, and replace member, and several non-member non-friend functions of the same name.

Does this mean, as I think it does, that Herb thinks some functions should be used with the dot notation, and others as a global function?

std::string s('foobar');  s.insert( ... ); /* One like this */ insert( s , ...); /* Others like this */ 

Edit:

Thanks everyone for your very useful answers, however, I think the point of my question has been overlooked.

I specifically did not mention the specific case of operators, and how they retain the ‘natural’ notation. Nor that you should wrap everything in a namespace. These things are written in the article I linked to.

The question itself was:

In the article, Herb suggests that one insert() method be a member, while the rest are non-member non-friend functions.

This implies that to use one form of insert() you have to use dot notation, while for the others, you do not.

Is it just me, or does that sound crazy?

I have a hunch that perhaps you can use a single syntax. (Im thinking how Boost::function can take a *this parameter for mem_fun).

  • 1 1 Answer
  • 1 View
  • 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. 2026-05-10T23:20:52+00:00Added an answer on May 10, 2026 at 11:20 pm

    You can use a single syntax, but perhaps not the one you like. Instead of placing one insert() inside your class scope, you make it a friend of your class. Now you can write

    mystring s; insert(s, 'hello'); insert(s, other_s.begin(), other_s.end()); insert(s, 10, '.'); 

    For any non-virtual, public method, it’s equivalent to define it as a non-member friend function. If mixed dot/no-dot syntax bothers you then by all means make those methods friend functions instead. There’s no difference.

    In the future we will also be able to write polymorphic functions like this, so maybe this is the C++ way, rather than artificially trying to force free functions into the dot syntax.

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

Sidebar

Related Questions

Is there a logical way to strip out function names and their arguments using
Sometimes I see people use http://codepad.org as a way to quickly run/test their Perl
Is there any way I can log a Wordpress user in given only their
How would you suggest using AsEnumerable on a non-generic IQueryable ? I cannot use
I currently use this function to wrap executing commands and logging their execution, and
Is their any way of counting number of django logins? The last_login field of
Is their a way to add all files that arent present with svn example.
I need a way to transform numeric HTML entities into their plain-text character equivalent.
Is there a generic way of determining all attributes (and their values) from an
is there a way how to convert HTML entities to their applicable characters. Something

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.