Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   An unhandled exception of type 'System.NullReferenceException' occurred (http://www.velocityreviews.com/forums/t449384-an-unhandled-exception-of-type-system-nullreferenceexception-occurred.html)

erictham115@gmail.com 10-27-2005 08:01 AM

An unhandled exception of type 'System.NullReferenceException' occurred
 
Hi i am a novice in C++ programming and encountered the following
problem without headway - a popout appeared after successful
compilation and linking with:
"An unhandled exception of type 'System.NullReferenceException'
occurred in rational.exe
Additional information: Object reference not set to an instance of an
object."

On pressing break, the code stopped at the fract[0] which is a private
class Rational member:

int* rational::setrational(int n, int d)
{
div_t div_result;
const int size = 3;
if (n > d )
{
div_result = div(n,d);
fract[0]= div_result.quot; --> code execution stopped here
fract[1]= div_result.rem;
fract[2]= d;
}
else
{
fract[0]= 0; <---- or here.
fract[1]= n;
fract[2]= d;

};

return fract;

Can anyone help? thanks


Ian 10-27-2005 08:31 AM

Re: An unhandled exception of type 'System.NullReferenceException'occurred
 
erictham115@gmail.com wrote:
> Hi i am a novice in C++ programming and encountered the following
> problem without headway - a popout appeared after successful
> compilation and linking with:
> "An unhandled exception of type 'System.NullReferenceException'
> occurred in rational.exe
> Additional information: Object reference not set to an instance of an
> object."
>
> On pressing break, the code stopped at the fract[0] which is a private
> class Rational member:
>

Does the array fract exist? Has it been initialised, or simply declared?

Ian

John Harrison 10-27-2005 06:35 PM

Re: An unhandled exception of type 'System.NullReferenceException'occurred
 
erictham115@gmail.com wrote:
> Hi i am a novice in C++ programming and encountered the following
> problem without headway - a popout appeared after successful
> compilation and linking with:
> "An unhandled exception of type 'System.NullReferenceException'
> occurred in rational.exe
> Additional information: Object reference not set to an instance of an
> object."
>
> On pressing break, the code stopped at the fract[0] which is a private
> class Rational member:
>
> int* rational::setrational(int n, int d)
> {
> div_t div_result;
> const int size = 3;
> if (n > d )
> {
> div_result = div(n,d);
> fract[0]= div_result.quot; --> code execution stopped here
> fract[1]= div_result.rem;
> fract[2]= d;
> }
> else
> {
> fract[0]= 0; <---- or here.
> fract[1]= n;
> fract[2]= d;
>
> };
>
> return fract;
>
> Can anyone help? thanks
>


Presumably fract is a null pointer. How it got to be a null pointer and
what it should be instead is impossible to tell from the code posted.

john

Acken 10-28-2005 05:43 AM

Re: An unhandled exception of type 'System.NullReferenceException' occurred
 
Thanks John & Ian. Will follow your suggestion to check on the code...



All times are GMT. The time now is 10:27 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.