Sign in to follow this  

SOLVED: Creating an array of structs

This topic is 4355 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

When I try to create an array of a structure I am getting a System.NullReferenceException exception in my program. I'm using Visual C++.Net and the specific piece of code gets a count and attempts to allocate the array for the count. Am I missing something in the syntax of my allocation?
if(!pNode) return false;

xnl = pNode->ChildNodes;
if(!xnl) return false;

IEnumerator *ie = xnl->GetEnumerator();

_xmlTransaction[numTransactions]._payloads.numProperties = xnl->Count;

// THIS IS WHERE I GET THE ERROR
_xmlTransaction[numTransactions]._payloads._properties = new property[xnl->Count];    


This is the structure for "property"
// property info
struct property
{	
	property_address _address;	// the address for this property
	property_inspection *_inspections;	// a list of inspections
	int numInspections;	// the number of inspections 

	std::string property_type;
	std::string units;
};


[Edited by - jon723 on January 10, 2006 2:04:28 PM]

Share this post


Link to post
Share on other sites
the _xmlTransaction object is declared as:
This is an object for the class Transaction

Transaction *_xmlTransaction; // point to a number of transactions

and it get allocated as such:

_xmlTransaction = new Transaction[numTransactions];

Share this post


Link to post
Share on other sites
I solved my problem. It appears that the NullPointerReference exception was caused by the 'new' operator to allocate memory. The proper way to allocate memory was to use malloc. (This is one of those pet peeves I have against Micro$oft)

Share this post


Link to post
Share on other sites

This topic is 4355 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this