Refering to a template name



 DEVELOP > c-Plus-Plus > Refering to a template name

LINK TO THIS PAGE  


rating :  0   |  0


  Page 1 of 1

1

 
Topic: DEVELOP > c-Plus-Plus
User: "Dave"
Date: 22 Sep 2004 03:01:07 PM
Object: Refering to a template name
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
.

User: "Rob Williscroft"

Title: Re: Refering to a template name 22 Sep 2004 03:26:47 PM
Dave wrote in news:10l3mg23pqeoo36@news.supernews.com 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/
.

User: "Ioannis Vranos"

Title: Re: Refering to a template name 22 Sep 2004 03:06:38 PM
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
.


  Page 1 of 1

1

 


Related Articles
 

NEWER

pg.1232     pg.940     pg.716     pg.544     pg.412     pg.311     pg.234     pg.175     pg.130     pg.96     pg.70     pg.50     pg.35     pg.24     pg.16     pg.10     pg.6     pg.3     pg.1

OLDER