c++ - how can i access to a byte array of array of different size? -


i facing problem when try access array of array pointer, have several arrays declared following :

byte a[5] = {0xcc,0xaa,0xbb,0xcc,0xff}; byte b[3] = {0xaa,0xbb,0xff}; 

thos byte arrays represents image want load in memory dll, can access them separately no difficulty, want access them loop pointer ...

i tried put them array of array :

byte* c[2] = {a,b}; 

but when want loop through pointer c[i] doesent load image @ index memory, how fix it?

im trying draw images method within loop avoid repating lines ( consider c images[i])

void menuicon::drawicons(lpdirect3ddevice9 npdevice) {     ismenuvisible = (pos.x < 100) && (pos.x > 0)?  true : false;      if(ismenuvisible)     (int = 0; < 2; i++)     {         if (icon[i].img == null)d3dxcreatetexturefromfileinmemory(npdevice, &images[i], sizeof(images[i]), &icon[i].img);         drawtexture(icon[i].coord.x, icon[i].coord.y, icon[i].img);     }  } 

i try use method after reading answer :

 void menuicon::drawicons(lpdirect3ddevice9 npdevice) {     ismenuvisible = (pos.x < 100) && (pos.x > 0)?  true : false;      if(ismenuvisible)     (size_t = 0; < images.size(); i++)     {          std::vector<byte>& curarray = images[i];         if (icon[i].img == null)d3dxcreatetexturefromfileinmemory(npdevice, &curarray, curarray.size(), &icon[i].img);         drawtexture(icon[i].coord.x, icon[i].coord.y, icon[i].img);     }  } 

but still not drawing nothing .... maybe &curarray not called proprely?? nb -> logged both image , size of arrayofarray , return me correct values....

you can use std::vector:

#include <vector> #include <iostream> #include <iomanip>  typedef int byte; typedef std::vector<byte> bytearray; typedef std::vector<bytearray> arrayofbytearray;  using namespace std;  int main() {    // fill our array    arrayofbytearray c = {{0xcc,0xaa,0xbb,0xcc,0xff},                           {0xaa,0xbb,0xff}                          // add more desired...                          };     // loop on each entry    (size_t = 0; < c.size(); i++)    {       // byte array entry       std::vector<byte>& curarray = c[i];        // output values found array       (size_t j = 0; j < curarray.size(); ++j)          cout << std::hex << curarray[j] << " ";        cout << "\n";    } } 

live example

the std::vector knows sizes of each of entries, unlike array.

take code here , add suit you're attempting images.


Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -