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?
thisis a pointer, and yourplusfunction declares that it returns a value.You probably want to change the return type to
voidand 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:
now you can write:
if you really want to.