H
Huck Phin
OK, so I have looked and looked for something similar to my problem,
and I cannot find one. I am writing a program for a HugeInteger, and I
am attempting to overload the preincrement, postincrement,
predecrement, and postdecrement operators. I realize that they are
really all the same, and if I get one of the four operators working, I
can get the rest. I have overloaded all of the other operators such as
+, -, <, >, <=, etc. and there is no issue with that. I have tested my
class to work with a HugeInteger.add( otherHugeInteger ), and it works
fine. My endstate that I am looking for is for my program to print out
the value, and not terminate abnormally.
Here's the code that works for me.
// Preincrement operator
HugeInteger HugeInteger:perator++( int )
{
return *this;
}
As we all know, the preincrement requires that you need to add 1 to the
object, and then return this back. However, I have tried everything
but the right answer with no luck. So try to get my object to add
something, I tried this method.
// Preincrement operator
HugeIntege HugeInteger:perator++( int )
{
HugeInteger one( 1 ); // I have made a constructor to take in an
integer, which works also
cout << "*this: " << *this << endl; // Debug statements
*this = (*this).add( one );
cout << "*this: " << *this << endl; // Debug statements
cout << "testaroo..." << endl; // More debug statements
return *this;
}
When I attempt to run my program, I get the following output:
*this: 111
*this: 112
testaroo...
Then, my program terminates, and I get the following message.
"Unhandled exception at 0x00000000:"
"0xC0000005: Access violation reading location 0x00000000.
The exception that is unhandled is First-Chance Exception, which
I don't quite understand what that is. This is the root of my problem,
and I understand this.
So, what this tells me is that my preincrement works inside the
function,
but I cannot return that value. What can I do to fix this?
considering that when I return *this, I am merely returning my
instance of the HugeInteger.
Anyways, I am stuck, and am requesting some help. Thanks in
advance for the help.
and I cannot find one. I am writing a program for a HugeInteger, and I
am attempting to overload the preincrement, postincrement,
predecrement, and postdecrement operators. I realize that they are
really all the same, and if I get one of the four operators working, I
can get the rest. I have overloaded all of the other operators such as
+, -, <, >, <=, etc. and there is no issue with that. I have tested my
class to work with a HugeInteger.add( otherHugeInteger ), and it works
fine. My endstate that I am looking for is for my program to print out
the value, and not terminate abnormally.
Here's the code that works for me.
// Preincrement operator
HugeInteger HugeInteger:perator++( int )
{
return *this;
}
As we all know, the preincrement requires that you need to add 1 to the
object, and then return this back. However, I have tried everything
but the right answer with no luck. So try to get my object to add
something, I tried this method.
// Preincrement operator
HugeIntege HugeInteger:perator++( int )
{
HugeInteger one( 1 ); // I have made a constructor to take in an
integer, which works also
cout << "*this: " << *this << endl; // Debug statements
*this = (*this).add( one );
cout << "*this: " << *this << endl; // Debug statements
cout << "testaroo..." << endl; // More debug statements
return *this;
}
When I attempt to run my program, I get the following output:
*this: 111
*this: 112
testaroo...
Then, my program terminates, and I get the following message.
"Unhandled exception at 0x00000000:"
"0xC0000005: Access violation reading location 0x00000000.
The exception that is unhandled is First-Chance Exception, which
I don't quite understand what that is. This is the root of my problem,
and I understand this.
So, what this tells me is that my preincrement works inside the
function,
but I cannot return that value. What can I do to fix this?
is pointing to a null pointer. I don't understand how this can beFrom reading other posts, I gather that for some reason my program
considering that when I return *this, I am merely returning my
instance of the HugeInteger.
Anyways, I am stuck, and am requesting some help. Thanks in
advance for the help.