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

DUMB code problem in visual c++ 1

Status
Not open for further replies.

josphin

Programmer
Apr 5, 2003
19
BE
hi,
i want to declare a CArray in my prog. The array is meant to contain elements of the type CProducten (a class that i made myself) Am i doing this correct :

CArray <CProducten, CProducten> array[100];

???
Thx!
 
Should be

[tt]CArray <CProducten, CProducten&> array;
array.SetSize(100);[/tt]

if you say array[100], that means you want one hundred arrays. Remember a CArray is different from the basic array type.

Rather, use SetSize to initialize the size of the collection (not absolutely necessary, but faster to allocate a whole bunch of memory at once.)

Also note that I change the second template argument to [tt]CProducten&[/tt]. This is to keep the entire CProducten object from having to be pushed onto the stack in function calls... instead only a reference is returned.

Will
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top