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

Discussion in 'C++' started by Wayne Shu, Jan 29, 2007.

  1. Wayne Shu

    Wayne Shu Guest

    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]??
    Wayne Shu, Jan 29, 2007
    #1
    1. Advertising

  2. Wayne Shu

    Ian Collins Guest

    Re: It's strange that the address of array elements are not acceptabletemplate-arguments!!

    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.
    Ian Collins, Jan 29, 2007
    #2
    1. Advertising

  3. Wayne Shu

    Wayne Shu Guest

    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 <> 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.
    Wayne Shu, Jan 29, 2007
    #3
  4. Wayne Shu

    Noah Roberts Guest

    Re: It's strange that the address of array elements are not acceptabletemplate-arguments!!

    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 <> 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.
    Noah Roberts, Jan 29, 2007
    #4
  5. On Jan 28, 10:31 pm, Noah Roberts <> 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 <> 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.
    Markus Svilans, Jan 29, 2007
    #5
  6. Re: It's strange that the address of array elements are not acceptabletemplate-arguments!!

    * Markus Svilans:
    >
    > On Jan 28, 10:31 pm, Noah Roberts <> 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 <> 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?
    Alf P. Steinbach, Jan 29, 2007
    #6
  7. Wayne Shu

    Greg Herlihy Guest

    Re: It's strange that the address of array elements are notacceptable template-arguments!!

    On 1/28/07 6:15 PM, in article
    , "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
    Greg Herlihy, Jan 29, 2007
    #7
  8. Wayne Shu

    Noah Roberts Guest

    Re: It's strange that the address of array elements are not acceptabletemplate-arguments!!

    Markus Svilans wrote:
    >
    > On Jan 28, 10:31 pm, Noah Roberts <> 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 Roberts, Jan 29, 2007
    #8
  9. On Jan 29, 3:11 am, Noah Roberts <> wrote:
    > Markus Svilans wrote:
    >
    > > On Jan 28, 10:31 pm, Noah Roberts <> 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.
    Markus Svilans, Jan 29, 2007
    #9
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Victor Bazarov
    Replies:
    1
    Views:
    308
    Andrzej 'Foxy' D.
    May 2, 2006
  2. J. Muenchbourg
    Replies:
    1
    Views:
    143
  3. Tim Gaunt
    Replies:
    7
    Views:
    162
    Tim Gaunt
    Dec 18, 2003
  4. Jack
    Replies:
    1
    Views:
    204
    Ray Costanzo [MVP]
    Dec 14, 2004
  5. SyrUser03
    Replies:
    2
    Views:
    195
    Dthmtgod
    Mar 11, 2005
Loading...

Share This Page