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

  • Home
  • SEARCH
  • 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 7885991
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:12:34+00:00 2026-06-03T05:12:34+00:00

Today I looked into the header source code of boost::asio::ip::address and found the following

  • 0

Today I looked into the header source code of boost::asio::ip::address and found the following lines:

class address
{
  // I removed some irrelevant lines here...

  public:

  /// Compare addresses for ordering.
  friend bool operator>=(const address& a1, const address& a2)
  {
    return !(a1 < a2);
  }
};

Now I know what friend is for but I had never seen it followed by a definition, inside a class definition.

So my question is, what does this friend declaration do ? It seems to me that operator>= is not a method here, however there is no static keyword either.

Does friend replace static in this particular case ?

  • 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-03T05:12:35+00:00Added an answer on June 3, 2026 at 5:12 am

    Yes and no. It doesn’t replace static because you don’t need to qualify the name when you call the operator. It kind of does as you don’t need a class instance to call it on.

    It’s like declaring the operator outside the class:

    class address
    {
      // I removed some irrelevant lines here...
    
      public:
    
      /// Compare addresses for ordering.
      friend bool operator>=(const address& a1, const address& a2);
    };
    
    inline bool operator>=(const address& a1, const address& a2)
    {
       return !(a1 < a2);
    }
    

    You can access private and protected methods from the class.

    Think of overloading the stream operator inside the class, the same technique can be applied.

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

Sidebar

Related Questions

Today, I have looked into HTML code of facebook.com, and found something like this:
I looked at some Java code today, and I found some weird syntax: public
Today I looked at the ZipEntry class and found the following: public class ZipEntry
Today I've looked over some C code that was parsing data from a text
Today when I was doing some experiments with == , I accidentally found out
EDIT: following the first answer I have looked more into stackoverflow and rephrased the
I found something interesting today when opening VS2010 on my PC. It looked as
I was doing some work today, and came across an issue where something looked
This is probably a pretty dumb question, but earlier today I ran into some
Today, I ran into this weird problem with a user using Mac OS X.

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.