Jump to content
  • Advertisement
Sign in to follow this  

SOLVED: Creating an array of structs

This topic is 4695 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;

_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
Are you trying to create a dynamic array of structures? How are you declaring _xmlTransaction?


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
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!