template
<
typename T,
unsigned int size
void DoStuff1(
T (& array)[size]
)
{}
template
<
typename T,
unsigned int size
void DoStuff2(
T (* array_p)[size]
)
{}
struct Pod
{
int data[10];
};
int main ()
{
Pod pod;
DoStuff1(pod.da ta); // does not compile why ??
DoStuff2(&pod.d ata); // this one is fine in comparison to the
above
}
I am just confused as how come a function parameter taking a reference
to an array leads to the data array decaying into a pointer (so type
info is lost and code does not compile), where as the function which
is taking a call parameter of a pointer to an array can compile and
keep on holding the type info.
<
typename T,
unsigned int size
>
T (& array)[size]
)
{}
template
<
typename T,
unsigned int size
>
T (* array_p)[size]
)
{}
struct Pod
{
int data[10];
};
int main ()
{
Pod pod;
DoStuff1(pod.da ta); // does not compile why ??
DoStuff2(&pod.d ata); // this one is fine in comparison to the
above
}
I am just confused as how come a function parameter taking a reference
to an array leads to the data array decaying into a pointer (so type
info is lost and code does not compile), where as the function which
is taking a call parameter of a pointer to an array can compile and
keep on holding the type info.
Comment