Advertisement

How to...

Started by July 13, 2001 07:32 AM
3 comments, last by Frodo Baggins 23 years, 7 months ago
If anyone knows how to dynamically create an array of structures in c++ please let me know. Thanx.
struct EXAMPLE
{
float x,y;
};
EXAMP *exmp

//some code

exmp=new EXAMP[NUM_OF_ELEMTS];

//some more code
delete exmp; //when done
exmp=0;

HHSDrum@yahoo.com
Polarisoft Home Page
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
Advertisement
When you allocate with a

exmp=new EXAMP[NUM_OF_ELEMTS];

you should also delete with a
delete[] exmp;
because you allocate an array of EXAMP:s so the compiler knows you''re deallocating an array.



/JanneVee
"Some People even believe that COBOL is a real programming language." Scott Meyers - Effective C++
/JanneVee"Some People even believe that COBOL is a real programming language." Scott Meyers - Effective C++
Actually, I think most major compilers will let you get away with just plain ''delete'', but it''s still a good idea to use ''delete []''.
Thank you for the answers.

This topic is closed to new replies.

Advertisement