467,169 Members | 972 Online
Bytes | Developer Community
Ask Question

Home New Posts Topics Members FAQ

Post your question to a community of 467,169 developers. It's quick & easy.

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

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

Jan 29 '07 #1
  • viewed: 1338
Share:
8 Replies
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.
Try
C<arr*c2;

--
Ian Collins.
Jan 29 '07 #2
I know that the name of the array could be acceptable.
my question is why the elements of array can't be.

On Jan 29, 10:25 am, Ian Collins <ian-n...@hotmail.comwrote:
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.Try
C<arr*c2;

--
Ian Collins.
Jan 29 '07 #3
Wayne Shu wrote:
I know that the name of the array could be acceptable.
my question is why the elements of array can't be.

On Jan 29, 10:25 am, Ian Collins <ian-n...@hotmail.comwrote:
>Wayne Shu wrote:
>>Why there has such a rule for the template non-type argument??
>Try
C<arr*c2;
Please don't top post.
Jan 29 '07 #4


On Jan 28, 10:31 pm, Noah Roberts <nrobe...@example.netwrote:
Wayne Shu wrote:
I know that the name of the array could be acceptable.
my question is why the elements of array can't be.
On Jan 29, 10:25 am, Ian Collins <ian-n...@hotmail.comwrote:
Wayne Shu wrote:
Why there has such a rule for the template non-type argument??
Try
C<arr*c2;


Please don't top post.
What a helpful response.

Jan 29 '07 #5
* Markus Svilans:
>
On Jan 28, 10:31 pm, Noah Roberts <nrobe...@example.netwrote:
>Wayne Shu wrote:
>>I know that the name of the array could be acceptable.
my question is why the elements of array can't be.
On Jan 29, 10:25 am, Ian Collins <ian-n...@hotmail.comwrote:
Wayne Shu wrote:
Why there has such a rule for the template non-type argument??
Try
C<arr*c2;

Please don't top post.

What a helpful response.
Please read the FAQ before posting.

--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?
Jan 29 '07 #6
On 1/28/07 6:15 PM, in article
11**********************@s48g2000cws.googlegroups. com, "Wayne Shu"
<Wa******@gmail.comwrote:
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

Jan 29 '07 #7
Markus Svilans wrote:
>
On Jan 28, 10:31 pm, Noah Roberts <nrobe...@example.netwrote:
>Please don't top post.

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?
Jan 29 '07 #8
On Jan 29, 3:11 am, Noah Roberts <nrobe...@example.netwrote:
Markus Svilans wrote:
On Jan 28, 10:31 pm, Noah Roberts <nrobe...@example.netwrote:
Please don't top post.
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?
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.

Jan 29 '07 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by trevorelbourne@gmail.com | last post: by
24 posts views Thread by RyanTaylor | last post: by
5 posts views Thread by ashraftm@gmail.com | last post: by
6 posts views Thread by Kumar | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.