473,378 Members | 1,631 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

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
8 1527
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Paul | last post by:
Please help, I am working on an Active-x project involving Arrays with up to 20 elements populated in a class module. In order to keep programming and debugging simple, Instead of refering to...
6
by: Herrcho | last post by:
in K&R Chapter 6.3 it mentions two methods to calculate NKEYS. and points out the first one which is to terminate the list of initializers with a null pointer, then loop along keytab until the...
3
by: trevorelbourne | last post by:
Hi, I am having trouble accessing the elements of an array using reflection. This is the code I am having trouble with: FieldInfo Fields = Obj.GetType().GetFields(); foreach (FieldInfo fi in...
8
by: ljlevend2 | last post by:
If a property's type is an array and the property is exposed in a PropertyGrid, then the property can be expanded so that the user can view and edit the array elements. But, I've noticed that if...
24
by: RyanTaylor | last post by:
I have a final coming up later this week in my beginning Java class and my prof has decided to give us possible Javascript code we may have to write. Problem is, we didn't really cover JS and what...
5
by: ashraftm | last post by:
How do I get Array elements value from Reflection.. Here is the C# code.. I have 2 struc Public struct Address { public string city; }
6
by: Kumar | last post by:
How should I declare the array elements being half word? and the array elements of the type byte in C?? Please help Kumar
14
by: dan | last post by:
I would like to have the preprocessor automatically generate the number of array elements requested. Each element is zero. The elements get pasted into a larger array. The other elements may be...
1
by: simply123 | last post by:
I doing doing C btw... i have been trying to convert array elements into their respective addresses but Im faced with many problems. eg. int x (array with 7 elements) im trying to set the...
2
by: awaisworld13 | last post by:
I want to write a program which take input and save the poistions of the array elements in another array. let if i enter an array A= 4 A=1 A=2 A=3 now the output array will hold 1 2 3
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.