Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

static const data w/ variable len arrays

By: a guest on Sep 25th, 2011  |  syntax: C++  |  size: 0.68 KB  |  views: 58  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. // in .h file
  2.     struct Product
  3.     {
  4.         int m_price;
  5.         int const * m_availability;
  6.         //.... (more)
  7.     };
  8.     extern const Product product_array[];
  9.     extern const int     product_array_nbr;
  10.  
  11. // in .cpp file
  12.     const int avail1[] = {1,2,3};
  13.     const int avail2[] = {2, 3, 5, 7, 11, 13};
  14.     const int avail3[] = {42};
  15.  
  16.     const Product product_array[] =
  17.     {
  18.         {
  19.              23,
  20.              avail1,
  21.              //....(more)
  22.         },
  23.         {
  24.              24,
  25.              avail2,
  26.              //....(more)
  27.         },
  28.         //....(more)
  29.     };
  30.  
  31.     const int product_array_nbr = sizeof(product_array)/sizeof(product_array[0]);
clone this paste RAW Paste Data