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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:50:32+00:00 2026-05-22T14:50:32+00:00

Im having trouble figuring out where to place the overloaded operators i created. should

  • 0

Im having trouble figuring out where to place the overloaded operators i created. should they be in the class they operate on, or inside? both ways are causing me trouble. any pointers would be great.

here is my very basic uint128_t class:

class uint128_t{
    private:
        uint64_t UPPER, LOWER;

    public:
    // constructors
        uint128_t(){
            UPPER = 0;
            LOWER = 0;
        }

        template <typename T>
        uint128_t(T val){
            UPPER = 0;
            LOWER = (uint64_t) val;
        }

        template <typename S, typename T>
        uint128_t(const S & upper_val, const T & lower_val){
            UPPER = (uint64_t) upper_val;
            LOWER = (uint64_t) lower_val;
        }

        uint128_t(uint128_t val){
            UPPER = val.upper();
            LOWER = val.lower();
        }

        uint64_t upper(){
            return UPPER;
        }

        uint64_t lower(){
            return LOWER;
        }
};

if the operators are in the class, they work fine. however, i can do uint128_t ^ uint32_t but not uint32_t ^ uint128_t. on the other hand, moving everything outside is giving me error: 'uint128_t operator=(uint128_t, T)' must be a nonstatic member function. also, operator= will not work for a constant input apparently, since the values will be ULLL, which doesnt exist, unless someone know of a way to do so.

what should i do?

  • 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-22T14:50:33+00:00Added an answer on May 22, 2026 at 2:50 pm

    Why not a mix of both?
    Put operator= inside, and the rest outside.

    For the ones that take uint128_t as left-hand-side argument it doesn’t matter, if it’s a right-hand-side argument then it has to be a global function. So for that reason you can put both functions side-by-side if they’re global. You might even get away with a clever macro to have one implementation for both, if only for the commutative ones.

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

Sidebar

Related Questions

im having trouble figuring out how to be able to access the methods inside
im having trouble figuring out how to bind mouseout() to my entire nav bar
I'm having trouble figuring out how to get the testing framework set up and
I'm having trouble figuring out how to access a cookie from a compiled object.
I'm having trouble figuring out how to delete a set of records when a
I'm having trouble figuring out a way to conditionally cancel an asp:TextBox's OnTextChanged AutoPostBack
I'm having trouble figuring out how to create a foreign key constraint. My data
I'm having trouble figuring out how to exclude /public/bin from this rewrite rule RewriteCond
I'm having trouble figuring out how to represent the following JPQL query: SELECT count(e)
I'm experimenting with Linq and am having trouble figuring out grouping. I've gone through

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.