L
Looney
template
<
typename T,
unsigned int sizevoid DoStuff1(
T (& array)[size]
)
{}
template
<
typename T,
unsigned int sizevoid DoStuff2(
T (* array_p)[size]
)
{}
struct Pod
{
int data[10];
};
int main ()
{
Pod pod;
DoStuff1(pod.data); // does not compile why ??
DoStuff2(&pod.data); // 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 sizevoid DoStuff1(
T (& array)[size]
)
{}
template
<
typename T,
unsigned int sizevoid DoStuff2(
T (* array_p)[size]
)
{}
struct Pod
{
int data[10];
};
int main ()
{
Pod pod;
DoStuff1(pod.data); // does not compile why ??
DoStuff2(&pod.data); // 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.