Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > It's strange that the address of array elements are not acceptable template-arguments!!

Reply
Thread Tools

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

 
 
Wayne Shu
Guest
Posts: n/a
 
      01-29-2007
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]??

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      01-29-2007
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.
 
Reply With Quote
 
 
 
 
Wayne Shu
Guest
Posts: n/a
 
      01-29-2007
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 <(E-Mail Removed)> wrote:
> 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.


 
Reply With Quote
 
Noah Roberts
Guest
Posts: n/a
 
      01-29-2007
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 <(E-Mail Removed)> wrote:
>> Wayne Shu wrote:
>>> Why there has such a rule for the template non-type argument??


>> Try
>> C<arr> *c2;


Please don't top post.
 
Reply With Quote
 
Markus Svilans
Guest
Posts: n/a
 
      01-29-2007


On Jan 28, 10:31 pm, Noah Roberts <(E-Mail Removed)> wrote:
> 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 <(E-Mail Removed)> wrote:
> >> 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.

 
Reply With Quote
 
Alf P. Steinbach
Guest
Posts: n/a
 
      01-29-2007
* Markus Svilans:
>
> On Jan 28, 10:31 pm, Noah Roberts <(E-Mail Removed)> wrote:
>> 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 <(E-Mail Removed)> wrote:
>>>> 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?
 
Reply With Quote
 
Greg Herlihy
Guest
Posts: n/a
 
      01-29-2007
On 1/28/07 6:15 PM, in article
(E-Mail Removed). com, "Wayne Shu"
<(E-Mail Removed)> 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

 
Reply With Quote
 
Noah Roberts
Guest
Posts: n/a
 
      01-29-2007
Markus Svilans wrote:
>
> On Jan 28, 10:31 pm, Noah Roberts <(E-Mail Removed)> wrote:
>
>> 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?
 
Reply With Quote
 
Markus Svilans
Guest
Posts: n/a
 
      01-29-2007
On Jan 29, 3:11 am, Noah Roberts <(E-Mail Removed)> wrote:
> Markus Svilans wrote:
>
> > On Jan 28, 10:31 pm, Noah Roberts <(E-Mail Removed)> wrote:

>
> >> 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
problem in running a basic code in python 3.3.0 that includes HTML file Satabdi Mukherjee Python 1 04-04-2013 07:48 PM
Address of array && address of pointer to array Stanley Rice C Programming 33 09-20-2011 12:47 AM
Not quite standard... but socially acceptable Tomás Ó hÉilidhe C Programming 20 04-04-2008 10:46 PM
type 'slice' is not an acceptable base type Antoon Pardon Python 2 12-21-2005 09:36 AM
huge numbers are not acceptable , why? ArShAm C++ 6 11-10-2003 05:28 PM



Advertisments