简体   繁体   中英

Taking the address of an overloaded function template

I have a function template getDescriptor with two overloads. They have the following signatures:

template <class _DescriptorType>
typename _DescriptorType::FeatureType getDescriptor
(const View & view, const _DescriptorType & desc);

and

template <class _DescriptorType>
typename _DescriptorType::FeatureType getDescriptor
(const Instance & instance, const _DescriptorType & desc);

I have a different function template getEncoding in which I need the address of the first getDescriptor function, with the _DescriptorType from getEncoding :

template <class _DescriptorType>
Encoding getEncoding()
{
    auto ptr = static_cast<...>(getDescriptor);

    ...
}

What do I need to put in the static_cast to get the address of the second overloaded getDescriptor template, with the _DescriptorType set to the one of getEncoding ?

There you go :

auto ptr = static_cast<
    typename _DescriptorType::FeatureType (*)(const Instance &, const _DescriptorType &)
>(getDescriptor<_DescriptorType>);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM