triple pointer help

i have this

type **a = NULL; // i need use as this a[i]->foo();

void alloc_it(type ***b, int c)
{
for(int i=0; i<c; i++)
*mem[i]=new type();
}

but it crash :S
"mem" is undeclared in this scope, unless it's a global variable, which you shouldn't do with dynamicly allocated memory without a bunch of bounds checks.
sorry i wrote it from scratch... it's *b[i]=new type();
Ok... "type()" does not name a data type. I'm not even compiling this yet, I can tell just by looking at it you're pretty far off base.

Are you sure a class with a constructor wouldn't be a better move for you?
type is a structure

struct type
{
type() : p(0) {}
~type() delete p; {}

void foo();

void *p;
};

now i tryied:

void _alloc(type **b)
{
(*b)=new type();
}

void alloc_it(type ***b, int c)
{
b=new type*[c];
for(int i=0; i<c; i++)
_alloc(&(*b)[i]);
}

but now is crashing only in release mode...
Sorry if this is off topic but I need to ask everytime I see a void pointer like that. Are you trying to write a class that is able to deal with multiple data types? Do you know how to write a class template?
I know but let me tell you what i'm trying to do.
In fact i'm writing a class that parse in memory a file.

my code is like that

MemoryFile **files;

int WriteAllFilesInMemory(MemoryFile ***files)
{
// here i need alloc the pointer. I know how many files there are and the size of a single file


}
Last edited on
Topic archived. No new replies allowed.