Advertisement
Guest User

static const data w/ variable len arrays

a guest
Sep 25th, 2011
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.68 KB | None | 0 0
  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]);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement