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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T12:02:06+00:00 2026-06-13T12:02:06+00:00

I was testing out classes and I made this class class Point { private:

  • 0

I was testing out classes and I made this class

class Point
{
private:
    int x,y;
public:
    void setit(int new_x,int new_y);
    void set_x(int new_x);
    void set_y(int new_y);
    int get_x();
    int get_y();
};

now I went ahead and wrote the function definitions for all the public functions but,

There is something that puzzled me when i was writing the void set(int new_x,int new_y);
function definition

void Point::setit(int new_x, int new_y){
    Point::set_x(new_x);
    Point::set_y(new_y);
}

void Point::setit(int new_x, int new_y){
    set_x(new_x);
    set_y(new_y);
}

I noticed that the two previous function definitions have the exact same effect.

I thought that without the :: operator it wouldn’t work because it would search for the functions outside the class, since I no longer signify they are in the Point class

Can anyone explain why they both have the same effect??

Thank You.

  • 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-13T12:02:07+00:00Added an answer on June 13, 2026 at 12:02 pm

    :: is the scope resolution operator; it can tell the compiler exactly where to look for a name.

    The Point::set_x is simply an extended syntax for calling a member function.

    set_x(new_x);
    

    Is short for

    this->set_x(new_x);
    

    And

    Point::set_x(new_x);
    

    Is equivalent for

    this->Point::set_x(new_x);
    

    It allows you to select which function to call when a class hides a function in a parent class. For instance:

    struct A {
        void f();
    };
    
    struct B : public A {
        void f(); // Hides A::f
    };
    
    B binst;
    
    binst.f(); // Calls B::f
    
    binst.A::f(); // Calls A::f
    

    One thing you can do with this syntax is call the member function of a parent class from the overridden virtual function of a base class, allowing you to use the “default implementation” provided by the base class. You can also do it from outside the class, similar to hidden functions:

    struct A {
        virtual void f() {
            cout << "A::f" << endl;
        }
    };
    
    struct B : public A {
        virtual void f() override {
            cout << "B::f" << endl;
    
            A::f(); // if we just did f(), it would call B::f, and we
                    // would get infinite recursion
        }
    };
    
    B b;
    
    b.f();    // prints B::f A::f
    b.A::f(); // prints B::f
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Before describing the problem, let me first point out that this is a distinct
Say I have the following classes public class TestA { public string Blah {
I'm currently learning php, and I'm testing out oop and classes. My code is:
I have two classes: namespace Something { [Serializable] public class Spec { public string
Testing out someone elses code, I noticed a few JSP pages printing funky non-ASCII
In testing out our API, one of our testers found out that when they
I'm testing out faults and exception handling on my service and am seeing odd
I was testing out RQ (Redis-Queue) when after running the command rqworker and testing
I'm testing out the OpenERP 6.1 web client, and I sometimes have a sales
i'm just testing out the csv component in python, and i am having some

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.