SOLVED: Creating an array of structs

Started by
4 comments, last by jon723 18 years, 3 months ago
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]
www.lefthandinteractive.net
Advertisement
Are you trying to create a dynamic array of structures? How are you declaring _xmlTransaction?


xeddiex.
one..
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];
www.lefthandinteractive.net
Can I ask why you're not using a vector for this? You're using strings already.

"Those who would give up essential liberty to purchase a little temporary safety deserve neither liberty nor safety." --Benjamin Franklin

Could you post all your structures? "_payloads" "_xmlTansaction"
We should do this the Microsoft way: "WAHOOOO!!! IT COMPILES! SHIP IT!"
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)
www.lefthandinteractive.net

This topic is closed to new replies.

Advertisement