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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:31:39+00:00 2026-05-14T18:31:39+00:00

I’m having some issues with implementing a logarithm class with operator overloading in C++.

  • 0

I’m having some issues with implementing a logarithm class with operator overloading in C++.

My first goal is how I would implement the changeBase method, I’ve been having a tough time wrapping my head around it.

I have tried to understand the math behind changing the base of a logarithm, but i haven’t been able to. Can someone please explain it to me?

My second goal is to be able to perform an operation where the left operand is a double and the right operand is a logarithm object.

Here’s a snippet of my log class:

// coefficient: double
// base: unsigned int
// result: double
class _log {

 double coefficient, result;
 unsigned int base;

public:

 _log() {
  base = 10;
  coefficient = 0.0;
  result = 0.0;
 }
 _log operator+ ( const double b ) const;
 _log operator* ( const double b ) const;
 _log operator- ( const double b ) const;
 _log operator/ ( const double b ) const;
 _log operator<< ( const _log &b );

 double getValue() const;

 bool changeBase( unsigned int base );
};

You guys are awesome, thank you for your time.

  • 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-14T18:31:39+00:00Added an answer on May 14, 2026 at 6:31 pm

    A few things

    1. Using an _ in the front of your class is a Very Bad Idea ™. From the c++ standard:

    17.4.3.2.1 Global names [lib.global.names]
    Certain sets of names and function signatures are always reserved to the
    implementation:

    • Each name that contains a double underscore (_ _) or begins with
      an underscore followed by an uppercase
      letter (2.11) is reserved to the
      implementation for any use.
    • Each name that begins with an underscore is reserved to the
      implementation for use as a name in
      the global namespace.165

    165) Such names are also reserved in namespace ::std (17.4.3.1).

    1. I’m guessing that you used _log instead of log due to the clash with log() in cmath. It is a Very Bad Idea to keep your own classes in the standard namespace for this very reason. Maybe the next version of the standard will provide a _log or Logarithm class?
      Wrap your own class in namespace somename {} and reference it by using somename::Logarithm()

    2. As others have mentioned already You need to declare your operator overloading as friend. Instead of what you have

      log operator+ ( const double b ) const;

      change it to

      friend log operator+(const double d, const log& l);
      

      and define the function in the namespace scope.

    3. Here is the math for the change of base formula

      Change of base formula

    4. Coefficient in math means the part that is being multiplied by the log. So if you had
      A log_b(x) = y

      A is the coefficient, B is the base, and Y is the result (or some other names)

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

Sidebar

Ask A Question

Stats

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

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

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

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

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer What you've actually posted is that you've tried Announcement.tags. But… May 15, 2026 at 8:42 am
  • Editorial Team
    Editorial Team added an answer Try checking the first page you get when you login… May 15, 2026 at 8:42 am
  • Editorial Team
    Editorial Team added an answer Property files typically contain values for variables that are used… May 15, 2026 at 8:42 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.