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

|
Related Articles |
|
|