An unhandled exception of type 'System.NullReferenceException' occurred

E

erictham115

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
 
I

Ian

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
 
J

John Harrison

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top