Refering to a template name

D

Dave

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
 
I

Ioannis Vranos

Dave said:
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);
};
 
R

Rob Williscroft

Dave wrote in 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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top