I'm trying to create a structure that can be interacted with as if it were an int
. However, when I try to assign a value to it, it throws the following error upon compiling:
Invalid conversion from `int` to `int32*`
Why does it throw that error, even though I made it's =
operator to handle setting an int32
to a const int
value?
Here's the source code for my best attempt at int32
:
struct int32
{
int32_t val;
int32(int val=0)
: val(val)
{
}
int32& operator=(const int value) // ex. int32 *i = 42;
{
val=value;
return *this;
}
int32 operator+(const int32& value) const
{
return int32(value.val+val);
}
int32 operator-(const int32& value) const
{
return int32(value.val-val);
}
int32 operator*(const int32& value) const
{
return int32(value.val*val);
}
int32 operator/(const int32& value) const
{
return int32(value.val/val);
}
int32 operator%(const int32& value) const
{
return int32(value.val%val);
}
bool operator==(const int32& value) const
{
return (val == value.val);
}
bool operator!=(const int32& value) const
{
return (val != value.val);
}
}
Also, please don't just recommend I use int32_t
; I'm making my own struct
for a reason (otherwise I'd have just used int32_t
to begin with ;)
int32*
is the source of trouble (not shown here)int32*
and notint32
?int32 i = 42;
instead ofint32 *i = 42;
?