previous | start | next

2.6 Example (same template version; different element type)

int main()
{
  // declare an empty Array (of Point's)
  Array<Point> a;
  int x, y;

  srand((unsigned int) time(0)); // Initialize random number generator

  // Insert random Point's at the end
  for(int i = 0; i < 10000; i++) {
    x = rand();
    y = rand();
    a.add( Point(x,y) );
  }

  // Print the Points in the Array a
  // Assumes operator<< has been overloaded for Poitn

  for(int i = 0; i < a.size(); i++) {
     cout << a.at(i) << endl;
  }

  return 0;
}
 


previous | start | next