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:
Only subclass has implemented Serializable interface. import java.io.*; public class NewClass1{ private int i;
I have the following class: #include <array> template<unsigned short D> class Point { private:
Becase I've seen (and used) situations like this: In header.h: class point { public:
I have this code: public class Area { Texture2D point; Rectangle rect; SpriteBatch _sB;
In code I've seen, some people often use private variables, e.g. private static int
I have an arraylist of entities. The Entity class has public void update(int delta,
I have two classes set up as follows: class Point { protected: double coords[3];
i have bug that i cannot find, i have Class Point with method who
Say that I have an immutable Point class with x and y parameters, and

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.