It's strange that the address of array elements are not acceptable template-arguments!!

W

Wayne Shu

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]??
 
I

Ian Collins

Wayne said:
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.
Try
C<arr> *c2;
 
W

Wayne Shu

I know that the name of the array could be acceptable.
my question is why the elements of array can't be.

Wayne said:
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.Try
C<arr> *c2;
 
G

Greg Herlihy

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
 
N

Noah Roberts

Markus said:
What a helpful response.

Well, having me answer questions can be of benefit. I may not know
everything but I certainly know some things. Others here are much
smarter than I but will have the same reaction to top-posting...I'll
plonk you if you keep doing it as it is incredibly irritating trying to
converse with people that top-post as well as the fact that not
observing etiquette is rude and rude people don't deserve my help.

So yes, it was helpful. A short and to the point request to use proper
etiquette. Now the OP knows and can adjust their posting habits.

Now, do I need to put you in the killfile and label you as yet another
jerk who insists on being rude and argues with everyone who thinks it's
not ok or can we move on?
 
M

Markus Svilans

everything but I certainly know some things. Others here are much
smarter than I but will have the same reaction to top-posting...I'll
plonk you if you keep doing it as it is incredibly irritating trying to
converse with people that top-post as well as the fact that not
observing etiquette is rude and rude people don't deserve my help.

So yes, it was helpful. A short and to the point request to use proper
etiquette. Now the OP knows and can adjust their posting habits.

Now, do I need to put you in the killfile and label you as yet another
jerk who insists on being rude and argues with everyone who thinks it's
not ok or can we move on?

Noah,

I wish to extend my sincerest apologies for being rude, arguing with
everyone, and being a jerk. The last thing I intended to do was to
hurt anyone's feelings. Let us move on.

With warm regards,
Markus.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,575
Members
45,053
Latest member
billing-software

Latest Threads

Top