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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:49:24+00:00 2026-05-21T23:49:24+00:00

class Point { private int m_PointX; private int m_PointY; public Point(int x, int y)

  • 0
class Point
{
    private int m_PointX;
    private int m_PointY;

    public Point(int x, int y)
    {
        m_PointX = x;
        m_PointY = y;
    }

    public static Point operator+(Point point1, Point point2)
    {
        Point P = new Point();
        P.X = point1.X + point2.X;
        P.Y = point1.Y + point2.Y;

        return P;
    }
}

Example:

Point P1 = new Point(10,20);
Point P2 = new Point(30,40)
P1+P2; // operator overloading
  1. Is it necessary to always declare the operator overloading function as static? What is the reason behind this?
  2. If I want to overload + to accept the expression like 2+P2, how to do this?
  • 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-05-21T23:49:25+00:00Added an answer on May 21, 2026 at 11:49 pm
    1. Yes. Because you aren’t dealing with instances always with the operators.
    2. Just change the types to what you want.

    Here is an example for #2

    public static Point operator+(int value, Point point2)
    {
     // logic here.
    }
    

    You will have to do the other way with the parameters if you want P2 + 2 to work.

    See http://msdn.microsoft.com/en-us/library/8edha89s.aspx for more information.

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

Sidebar

Related Questions

Let's say I have a class Point: class Point { int x, y; public:
Becase I've seen (and used) situations like this: In header.h: class point { public:
In code I've seen, some people often use private variables, e.g. private static int
I'm trying to create a point class which defines a property called coordinate. However,
At what point would you create your own exception class vs. using java.lang.Exception? (All
What is the point of having a dynamic class on which you can call
Fragile base class is one of the most common point that gets popped up
I am writing a template class which takes a floating-point-like type (float, double, decimal,
I was wondering if anyone could point to an Open Source date utility class
interface ICanvasTool { void Motion(Point newLocation); void Tick(); } abstract class CanvasTool_BaseDraw : ICanvasTool

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.