Refering to a template name

Discussion in 'C++' started by Dave, Sep 22, 2004.

  1. Dave

    Dave Guest

    Hello,

    template <class T>
    class weak_ptr
    {
    weak_ptr(weak_ptr const &r);
    };

    In the code above, a parameter of type weak_ptr is declared. How is this
    possible? weak_ptr is not a type, it's a template! How can me use the name
    of a template as a data type?

    Thanks,
    Dave
     
    Dave, Sep 22, 2004
    #1
    1. Advertising

  2. Dave wrote:
    > Hello,
    >
    > template <class T>
    > class weak_ptr
    > {
    > weak_ptr(weak_ptr const &r);
    > };
    >
    > In the code above, a parameter of type weak_ptr is declared. How is this
    > possible? weak_ptr is not a type, it's a template! How can me use the name
    > of a template as a data type?




    For use inside a template definition you can ommit the type used, so the
    above could also have been written as:


    template <class T>
    class weak_ptr
    {
    weak_ptr<T>(weak_ptr<T> const &r);
    };



    --
    Ioannis Vranos

    http://www23.brinkster.com/noicys
     
    Ioannis Vranos, Sep 22, 2004
    #2
    1. Advertising

  3. Dave wrote in news: in comp.lang.c++:

    >
    > template <class T>
    > class weak_ptr
    > {
    > weak_ptr(weak_ptr const &r);
    > };
    >
    > In the code above, a parameter of type weak_ptr is declared. How is
    > this possible? weak_ptr is not a type, it's a template! How can me
    > use the name of a template as a data type?
    >


    In effect within the scope of weak_ptr< T > weak_ptr is an
    alias for weak_ptr< T >.

    I can't offhand remember the exact (standard text) of how this
    is done, but it is.

    IOW: That is how C++ is specified, the alternative would be:

    template < typename T >
    struct X
    {
    X< T >( X< T > const &x );
    };

    Which is just more typing, with no (AFAICT) percivable benefit.

    Rob.
    --
    http://www.victim-prime.dsl.pipex.com/
     
    Rob Williscroft, Sep 22, 2004
    #3
    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. =?Utf-8?B?TmljayBaZHVuaWM=?=

    Refering to web page class from another class

    =?Utf-8?B?TmljayBaZHVuaWM=?=, Feb 8, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    438
    Karl Seguin [MVP]
    Feb 8, 2006
  2. =?Utf-8?B?TmljayBaZHVuaWM=?=

    ASP.Net 2.0 - refering to the web page class

    =?Utf-8?B?TmljayBaZHVuaWM=?=, Feb 9, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    1,445
  3. =?Utf-8?B?Um9zcyBIb2xkZXI=?=

    Refering to Object Members in A Collection in an ASP.NET BoundColu

    =?Utf-8?B?Um9zcyBIb2xkZXI=?=, Mar 10, 2006, in forum: ASP .Net
    Replies:
    3
    Views:
    481
    =?Utf-8?B?Um9zcyBIb2xkZXI=?=
    Mar 10, 2006
  4. Sameer
    Replies:
    2
    Views:
    1,178
    Roedy Green
    Aug 28, 2005
  5. JJ
    Replies:
    4
    Views:
    471
Loading...

Share This Page