On 1/28/07 6:15 PM, in article
. com, "Wayne Shu"
<> wrote:
> Why there has such a rule for the template non-type argument??
>
> but address of an object of external linkage is acceptable!!
>
> e.g.
> template <int *p>
> class C;
>
> int i;
> int arr[10];
>
> C<&i> *c1; // ok, the address of an int with external linkage
> C<&arr[0]> *c2; // error, element of array is not acceptable.
>
> there is some difference between the i and arr[0]??
In the first case the non-type parameter has an name, "i" that uniquely
identifies the template argument. In the second case, the non-type parameter
has no name, only an address of an element within the "arr" array ("arr"
names the array, not a specific array element).
And unless the non-type parameter has a name, the compiler will not know for
sure whether two non-type parameters for the same template are identical or
not.
Greg