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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:52:09+00:00 2026-05-23T17:52:09+00:00

I am making a wrapper for a word in an emulator project. Its meant

  • 0

I am making a wrapper for a “word” in an emulator project. Its meant to put all my cast conversions all in one spot. I was just about to start implement all the overrides for math functions (+,-,/,8, shift, etc.) When it occured to me that shouldn’t all the implicit’s take care of that? Do I need to over ride >= and <= when I got > < and ==?

I thought I would ask this as while there are plenty of questions relating to how to create them, there aren’t many on how much is enough. Here is the code below:

public struct word_t
{
    ulong val;
    word_t(ulong val) { this.val = val; }
    public static implicit operator word_t(int a) { return new word_t((ulong)a); }
    public static implicit operator word_t(long a) { return new word_t((ulong)a); }
    public static implicit operator word_t(uint a) { return new word_t((ulong)a); }
    public static implicit operator word_t(ulong a) { return new word_t((ulong)a); }
    public static implicit operator int(word_t a) { return (int)a.val; }
    public static implicit operator long(word_t a) { return (long)a.val; }
    public static implicit operator uint(word_t a) { return (uint)a.val; }
    public static implicit operator ulong(word_t a) { return (ulong)a.val; }
    public static bool operator ==(word_t a, word_t b) { return a.val == b.val; }
    public static bool operator !=(word_t a, word_t b) { return a.val != b.val; }
    public static bool operator >(word_t a, word_t b) { return a.val > b.val; }
    public static bool operator <(word_t a, word_t b) { return a.val < b.val; }
    public override bool Equals(object obj) {
            return obj.Equals(val);
    }
    public override int GetHashCode() {
        return val.GetHashCode();
    }
    public override string toString() {
        return val.ToString();
    }
}

My gut tells me to “Trust the compiler” but my head always worries on how efficient it is.

PS I just realized I should override shifts because of the bit shifting of negative number problems, but for right now just imagine shifts just magically work like adds between uint and int.

  • 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-23T17:52:09+00:00Added an answer on May 23, 2026 at 5:52 pm

    I recommend this MSDN article: http://msdn.microsoft.com/en-us/library/8edha89s(v=VS.100).aspx

    It shows the operators you can overload and any catches. You can overload <= and >= but they must be overloaded in pairs, as is true with == and != as well.

    The complex match operators +=, etc are available if +, etc. is overloaded, etc.

    >= and <=, however, are separate. That is, overloading > and == does not give you a >= operator implicitly.

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

Sidebar

Related Questions

I have recently started making a C++ Wrapper of GTK+ (Nothing special, just wrapping
I'm making a wrapper for a forum API, one function returns this, which is
I tried making a wrapper class that encapsulates an object, a string (for naming
I'm making a wrapper of SQLite C API. And I want to return rowid
Has anyone managed to do this? I tried making a managed wrapper class for
I'm making a thread class to use as a wrapper for pthreads. I have
I'm making my first Rails project and I'm using the simple_form gem (version 1.0)
i am making a wrapper for my use for database, using Poco::Database::ODBC the normal
I am making some kind of wrapper around the TFS SDK. I would like
I'm making a template wrapper around std::set. Why do I get error for Begin()

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.