home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / CPROG / CGAZV5N3.ZIP / ARRAY.CPP < prev    next >
C/C++ Source or Header  |  1991-03-02  |  691b  |  23 lines

  1. //******** Listing 7 ********************** ARRAY.CPP ****
  2. // ARRAY.CPP : implementation of class dynamic_array
  3. // (c) C Gazette. See Listing 1 for usage.
  4. //********************************************************
  5.  
  6. #include "array.hpp"
  7. #include <stdio.h>
  8.  
  9. void dynamic_array::error(char * msg) {
  10.   fprintf(stderr, "dynamic_array error: %s\n", msg);
  11.   exit(1);
  12. }
  13. dynamic_array::dynamic_array(size_t sz) {
  14.   size = sz;
  15.   // can still use malloc and calloc if you want!
  16.   vec = (int*)calloc(sz, sizeof(int));  // cast required by C++
  17.   if(vec == NULL) error("out of memory in create_array");
  18. }
  19.  
  20. dynamic_array::~dynamic_array() {
  21.   free(vec); // free memory used for vec
  22. }
  23.