Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Null Reference

Status
Not open for further replies.

amw1

Programmer
Feb 9, 2005
12
0
0
US
I'm compiling in .net and I am new to this environment. Though familiar with C++, I would call myself only a small step or 2 above a newbie. Can someone please shine the light on what should be so obvious here? What am I doing wrong? BTW, all the cout is necessary because I am not yet able to run in debug mode, only release, as I don't yet have privileges (e.g. not yet part of the debugger's group).

void main
{
try
{
ObjectType objectUnderTest = new ObjectType();
objectUnderTest->performFunction();
}
catch(...)
{
cout<<"Exception thrown"<<endl;
}

}
-----------------------------------------
void ObjectType::performFunction()
{

OtherData data = getOtherData();

// this displays an address
// I can cout data pieces and they look fine
//
cout<<" &data is "<<endl;

// Call method to perform calculation
//
double result = supportingMethod(data);

// this prints a 0 address and any attempt to
// access it's data elements raises an exception
//
cout<<" &data is "<<endl;

// do more stuff here

}

double ObjectType::supportingMethod( const OtherData & inData ) const
{
double resultOfCalculation = 0.0;

// perform calculation based on input inData
//

return resultOfCalculation;
}

-------------------------
 
Well you didn't tell us the problem you're having (or where), so it's hard to tell. One thing I found strange is this:
Code:
ObjectType objectUnderTest = new ObjectType();
It looks like it should be this:
Code:
ObjectType* objectUnderTest = new ObjectType;
 
This is obivously not the actual exact code copied and pasted. Can you post something small and compilable that demonstrates the problem that you are having? The data variable is local to the function, and so taking the address of it should not return null unless you are corrupting your memory somehow.
 
Apropos: no such animal as Null Reference in C++
;-)...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top