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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:29:27+00:00 2026-05-22T17:29:27+00:00

The exact situation is next: I have defined in system API structs CGPoint and

  • 0

The exact situation is next:
I have defined in system API structs CGPoint and CGSize, and I want to be able to write my_point = my_size.
I can’t modify CGPoint struct, only can write external operator. I can write binary operators (+, -, …) but operator= must by declared inside struct. So is there any other solution?

  • 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-22T17:29:28+00:00Added an answer on May 22, 2026 at 5:29 pm

    To make the expression a = b; compile you need to either have an operator= in the type of a that takes an element of the type of b, or a type implicitly convertible from b.

    The first case is ruled out, since operator= must be a member of the class, and since you cannot modify GLPoint then you cannot add GLPoint& GLPoint::operator=( GLSize ).

    The second case suffers the same type of problems. An implicit conversion from GLSize to GLPoint can be implemented as an implicit constructor in GLPoint (ruled out), or as a member operator GLPoint() in GLSize, which requires modification of GLSize. Conversions cannot be added as free functions either.

    The alternatives are using non-operator syntax, as adding a free function assign (or copy): GLPoint& assign( GLPoint&, GLSize const & ).

    The next question is why would you want to do so. If the designers of GLPoint and GLSize did not consider that a size should be assignable to a point, then why do you feel that they should be assignable? In general it is a good idea to keep types separate, as that will enable the compiler to detect mistakes you might make in your code.

    If you allow implicit conversions from GLSize to GLPoint, you might by mistake type something like: distance( point1, size2 ) where you meant distance( point1, point2 ), and because there is a conversion, the compiler will gladly convert and apply. Then you will see strange results, and you will spend quite a few nice debugging hours trying to determine where the logic is wrong.

    Unless the domain has a very clear definition of what each operator means in that context, I would avoid operator overloading at all costs. Will everyone reading your code immediately understand what GLPoint(1,2) + GLSize(5) represents without any doubt or ambiguity? If that is not the case, if people will be surprised or even doubt, then avoid operator overloading and use named functions: move_up( GLPoint&, GLSize ) (or whatever point+size means to you)

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

Sidebar

Related Questions

I have this situation: I made 2 div's, both should be at the exact
I have a situation where i want to replicate the action of the keys
Situation: I have 3 tables: Student, Address, StudentAddressLink As follows Note* not EXACT yaml
This is a pretty odd situation I have here. I have used a piece
I have a very unique situation. We use a Cisco Web VPN (don't know
The situation: I have a pieceofcrapuous laptop. One of the things that make it
I have a situation utilizing class table inheritance where the base object (which is
Here is the situation, i have a website that can be accessed from multiple
I have the situation where I'm initializing my model in DatabaseInitializer() for EF 4.1
I have a common database joining situation involving three tables. One table, A, is

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.