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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

length of an array objects

Status
Not open for further replies.

sd110404

Programmer
Nov 3, 2004
63
US
Hi,

Can someone please assist/help me solve this problem, I tried my best all the help with the internet search. I will be really very thankful for any answers.

I have a class A{}; and class B {};

inside Class B, I need to have an array of pointers object for Class A (dimensions size 10). Class B contains methodB() that takes a pointer of A Class as a parameter and store the parameter value into the first unused slot in the array.

How to find out which slot if free. How to get the length of an array to traverse. I tried the floowing
sizeof(A1) where A1 was the array of pointer object for Class A.
Thanks for any help!

Thanks a lot.
 
Check out the "vector" template in stl, or do it yourself:

Remember the size of your array when you created it; resize if encessary etc. Put NULL values into the array so you can find the first available slot etc.

"vector" is the way to go though; much easier to use and them stl templates are hard to outperform with your own code

Greetings,
Rick
 
Thanks Rick. I will surely try with NULL. Thanks for your suggestion.
 
All pointers should ALWAYS be initialized to NULL until they are set to a real pointer value.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top