Jump to content
  • Advertisement
Sign in to follow this  
Zimans

Nested template declarations

This topic is 2662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I've been looking at the std::shared_ptr and boost::shared_ptr implementations recently trying to learn more advanced template programming and I've encountered a construct that I don't understand, and don't know what it is called to effectively search for it either. For example, here is a simplified snippet from std::shared_ptr


template< class _Ty >
class shared_ptr
{
public:
template< class _Ux, class _Dx >
shared_ptr( _Ux *p, _Dx dt );
};


When I create a shared pointer I can specify a deletor, for example:
std::shared_ptr< char > p( malloc( 100 ), free );

The only template type I provide is that of the underlying pointer, in this case char, however the constructor has a template associated with it that seems to get inferred instead of implicitly being defined like the template for the whole class.

At a minimum what is this construct called so I can at least better search for it. Searching for nested templates predominately gives me results on polymorphism with templates.

Can anyone explain to me how the secondary types _Ux and _Dx are inferred?

Thanks,
--Z

Share this post


Link to post
Share on other sites
Advertisement
After posting this I struck on the answer. The template types for functions can be inferred, but not those for classes, hence the nesting used by shared_ptr.

--Z

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!