Thomas Hede Jensen wrote:[color=blue]
>
> Hi,
>
> I'm currently working on a project in which I link to a library where the
> function definitions takes parameters of the type: "const int *const
> *paramName"[/color]
Thats a pointer to a pointer or a pointer to an array of pointers.
[color=blue]
> As far as I can tell from the example of usage this type definition requires
> a const int array,[/color]
It requires a pointer to an array of pointers
[color=blue]
> however, I do not know the size of those arrays at
> compile time (due to the nature of other parts of my code), thus I have to
> dynamically allocate the arrays by using "new". Passing parameters of this
> type results in the compiler error:
> 'Create' : none of the 4 overloads can convert parameter 3 from type 'int *'
>
> I have tried type casting or reinterpret_cast, none of which works, also I
> tried passing the parameters as "**int", this compiles, but this throws an
> exception at runtime.[/color]
casting won't help if the argument types don't fit in principle.
Assuming: The function wants a pointer to an array of pointers.
void foo( const int *const *paramName )
{
}
int main()
{
int Size = 20;
int Size2 = 40;
int** pArg = new int* [ Size ];
for( int i = 0; i < Size; ++i )
pArg[i] = new int [ Size2 ];
foo( pArg );
for( int i = 0; i < Size; ++i )
delete [] pArg[i];
delete [] pArg;
return 1;
}
--
Karl Heinz Buchegger
kbuchegg@gascad.at