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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:42:36+00:00 2026-06-14T16:42:36+00:00

Lets take some code samples: ! 4 > 0; From C++ standard we know,

  • 0

Lets take some code samples:

! 4 > 0;

From C++ standard we know, that negation will be done first, than comparison. But if we expand this example a little:

#include <iostream>

class Test
{
public:
    bool operator!() const
    {
            std::cout << "operator!" << std::endl;
            return false;
    }

    bool operator>(const int &) const
    {
            std::cout << "operator>" << std::endl;
            return false;
    }
};


int main(int argc, char * argv[])
{
    Test t;
    std::cout << "t > 0;" << std::endl;
    t > 0;
    std::cout << "! t > 0;" << std::endl;
    ! t > 0;
    std::cout << "!t.operator>(0)" << std::endl;
    ! t.operator>(0);

    return 0;
}

Output of this program will be:

t > 0;
operator>
! t > 0;
operator!
!t.operator>(0)
operator>
  1. First call (control call) is quite clear. We check if operator we want is called.
  2. Second call is proof of what I stated first. negation operator is called first, than on result (bool) operator> is called.
  3. Third call is what bothers me.

And here pops my question. Why SomeObjInstance > 0 call is different from SomeObjInstance.operator>(0). I know that it’s not common to call operators in second manner (as members), but why this calls differs? I always tought that SomeObjInstance > 0 is translated under the hood to member call SomeObjInstance.operator>(0) or function call bool operator>(const Test &, int) if member operator is not present.

Where this behaviour is described in C++ standard, or maybe is this some kind of undefined behaviour?

  • 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-14T16:42:38+00:00Added an answer on June 14, 2026 at 4:42 pm

    The member access operator .* has a higher precedence than the negation operator !.

    Where this behaviour is described in C++ standard, or maybe is this some kind of undefined behaviour?

    This is most likely the relevant paragraph:

    13.5 Overloaded operators [over.oper]

    5) Operator functions are usually not called directly; instead they are invoked to evaluate the operators they implement (13.5.1 – 13.5.7). They can be explicitly called, however, using the operator-function-id as the name of the function in the function call syntax (5.2.2).

    In your first example t > 0; it will use the according operator with the precedence for the relational comparison operators. However, in your second version t.operator>(0) you use it as a function call. Thereby the Test::operator> is used as a member function, which will result in your described behavior, as it looses its operator characteristics (“they can be explicitly called, however, using the operator-function-id as the name of the function in the function call syntax”).

    See also:

    • C++ Operator Precedence
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm creating an app that lets users take and store photos in a Core
I currently have an iPhone app that lets the users take video, upload it
Lets say I have a bit of javascript code that is passed a string
Lets say I have a function that needs to return some integer value. but
So lets take a look onto a littel bit modified example code: #include <stdio.h>
Hello I have a jQuery function that will send to a php file some
I am using Beautiful Soup to extract 'content' from web pages. I know some
I have some code that does a lot of comparisons of 64-bit integers, however
I have a function (say foo() )that will be called from time to time
Lets take stackoverflow as an example: Post Postid Title Mess -------------------------------------------------- 1 Title1 This

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.