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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:47:57+00:00 2026-05-14T15:47:57+00:00

I’m trying to write a class that implements 64-bit ints for a compiler that

  • 0

I’m trying to write a class that implements 64-bit ints for a compiler that doesn’t support long long, to be used in existing code. Basically, I should be able to have a typedef somewhere that selects whether I want to use long long or my class, and everything else should compile and work.

So, I obviously need conversion constructors from int, long, etc., and the respective conversion operators (casts) to those types. This seems to cause errors with arithmetic operators. With native types, the compiler “knows” that when operator*(int, char) is called, it should promote the char to int and call operator*(int, int) (rather than casting the int to char, for example). In my case it gets confused between the various built-in operators and the ones I created.

It seems to me like if I could flag the conversion operators as explicit somehow, that it would solve the issue, but as far as I can tell the explicit keyword is only for constructors (and I can’t make constructors for built-in types).

So is there any way of marking the casts as explicit? Or am I barking up the wrong tree here and there’s another way of solving this? Or maybe I’m just doing something else wrong…

EDIT:

A little clarification on what I want to do: I have a project that uses 64-bit (‘long long`) operations in many places, and I am trying to port it to a platform that doesn’t have built-in support for 64-bit variables/operations. Even though I have the source for the project, I would really prefer not to have to go over the thousands of places where built-in operators and C-style casts are and change them around.

As for the code itself, the project has the following definitions and kinds of code:

typedef long long i64;  // I would like to only have to change this to use my class instead of "long long"

int a;
unsigned b;
int c = ((i64)a*b)>>32;

As for the class implementation, I have the following:

class Long64 {
public:

Long64();
Long64(const Long64&);
Long64(int);
Long64(long);
Long64(unsigned int);
Long64(unsigned long);

operator int() const;
operator long() const;
operator unsigned int() const;
operator unsigned long() const;

friend Long64 operator*(int l, const Long64& r);
friend Long64 operator*(const Long64& l, int r);
friend Long64 operator*(long l, const Long64& r);
friend Long64 operator*(const Long64& l, long r);
}
  • 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-14T15:47:57+00:00Added an answer on May 14, 2026 at 3:47 pm

    To avoid the compiler to be confused, you will help it by defining the combination of your class and the built-in types for all the arithmetic operator. For example for operator+, you will need to define + the unsigned ones

    MyClass operator+(char, MyClass const&);
    MyClass operator+(MyClass const&, char);
    MyClass operator+(short, MyClass const&);
    MyClass operator+(MyClass const&,short);
    MyClass operator+(MyClass const&,int);
    

    the compiler will prefer overloads that don’t need to use conversion operators.

    Of course all these methods will use the overload
    MyClass operator+(MyClass const&,MyClass const&);

    by explicitly converting one of the parameters to your class MyClass

    MyClass operator+(char c, MyClass const& m) { return MyClass(c)+m;}
    

    This is a little bit cumbersome, I know, but it should avoid the conflicts.

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

Sidebar

Ask A Question

Stats

  • Questions 393k
  • Answers 393k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should create your app in the facebook developer section… May 15, 2026 at 2:10 am
  • Editorial Team
    Editorial Team added an answer The thing is that there are code generators and object… May 15, 2026 at 2:10 am
  • Editorial Team
    Editorial Team added an answer I suspect it's tripping up on the OrderItemStatus. There is… May 15, 2026 at 2:10 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.