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

  • Home
  • SEARCH
  • 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 7525113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T03:26:56+00:00 2026-05-30T03:26:56+00:00

The code is written to implement a Bit class with some common functions. #include

  • 0

The code is written to implement a Bit class with some common functions.

#include <iostream>
#include <math.h>
using namespace std;

class Bit
{ 
    int width;
    int value;
    public:
        Bit(int v, int w)
        {
            value=v;
            width=w;
        }
        Bit(const Bit& b)
        {
            value= b.value;
            width= b.width;
        }
        int getWidth()
        {
            return width;
        }
        int getValue()
        {
            return value;
        }
        Bit plus(int newval)
        {
            value+=newval;
            if(value>=pow(2,width))
            cout<<"Overflow";
            return this;
        }
};

The error message is :

Conversion from 'Bit* const' to non-scalar type 'Bit' requested.

How can i remove the error?

  • 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-30T03:26:58+00:00Added an answer on May 30, 2026 at 3:26 am

    this is a pointer, and your plus function declares that it returns a value.

    You probably want to change the return type to void and not return anything; I can’t see a good reason to return a copy of the object.

    Perhaps you want to return a reference in order to chain calls:

    Bit & plus(int newval)        //< added &
    {
        value+=newval;
        if(value>=pow(2,width))
            cout<<"Overflow";
        return *this;             //< added *
    }
    

    now you can write:

    bit.plus(1).plus(3).plus(42);
    

    if you really want to.

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

Sidebar

Related Questions

I have some old code written in C for 16-bit using Borland C++ that
I'm trying to implement single sign-on for a web portal. I've written some code
I've sometimes seen code written like this : public class B1 { } public
I have this code written in .NET 4.0 using VS2010 Ultimate Beta 2: smtpClient.Send(mailMsg);
I've seen some horrific code written in Perl, but I can't make head nor
I am working on some code written by a co-worker who no longer works
I have some performance-heavy code that performs bit manipulations. It can be reduced to
I am trying to implement Python code I've written in Java and I want
I've got some (badly written) legacy code that I have to modify but I'm
i've written written a code for counting each byte frequency in binary file. Using

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.