Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / ACE / examples / APG / Containers / Array.cpp
blob180a159517d319179b4908aaa998d93fdb1e3012
1 #include "ace/OS_Memory.h"
2 #include "ace/Log_Msg.h"
3 // Listing 1 code/ch05
4 #include "ace/Containers.h"
5 #include "DataElement.h"
7 int ACE_TMAIN (int, ACE_TCHAR *[])
9 ACE_Array<DataElement*> arr (10);
10 DataElement *elem = 0;
11 // Allocate and insert elements.
12 for (int i = 0; i < 10; i++)
14 ACE_NEW_RETURN (elem, DataElement (i), -1);
15 arr[i] = elem;
18 // Checked access.
19 ACE_ASSERT (arr.set (elem, 11) == -1);
20 ACE_ASSERT (arr.get (elem, 11) == -1);
22 // Make a copy and compare to the original.
23 ACE_Array<DataElement*> copy = arr;
24 ACE_ASSERT (copy == arr);
26 ACE_Array<DataElement*>::ITERATOR iter (arr);
27 while (!iter.done ())
29 DataElement** data;
30 iter.next (data);
31 ACE_DEBUG ((LM_DEBUG,
32 ACE_TEXT ("%d\n"), (*data)->getData ()));
33 delete (*data);
34 iter.advance ();
36 return 0;
38 // Listing 1