I want to create a 2D array like the following.
char **dog = new char[480][640];
But it errors:
error C2440: 'initializing' : cannot convert from 'char (*)[640]' to 'char ** '
Types pointed to are unrelated; conversion requires reinterpret_cast, C-style cast or function-style cast
what do I need to do using "new"? (not using calloc, malloc or char dog[480][640];
)
char (*p)[640] = new char[480][640];
Note that a 2D array ofT
is not the same as an array of pointers to arrays ofT
. Oh, and rather usestd::vector
than rawnew
. Cheers & hth.,std::vector<std::array<char, 640> > dog(480);
vector
andarray
that way. I think I'd use justvector
all the way, forget about the micro-optimization possible witharray
, and as an added bonus get code that works with more current compilers. Cheers,