Template parameter cannot be deduced

前端 未结 1 940
慢半拍i
慢半拍i 2020-12-06 12:17

I don\'t understand why T cannot be deduced in this scenario:

template
class MyType
{
    T * data;
};

class MyOtherType
{
};

template

        
相关标签:
1条回答
  • 2020-12-06 12:44

    This is because your case is a Non-deduced contexts.

    Cited from http://en.cppreference.com/w/cpp/language/template_argument_deduction:

    Non-deduced contexts

    In the following cases, the types, templates, and non-type values that are used to compose P do not participate in template argument deduction, but instead use the template arguments that were either deduced elsewhere or explicitly specified. If a template parameter is used only in non-deduced contexts and is not explicitly specified, template argument deduction fails.

    1) The nested-name-specifier (everything to the left of the scope resolution operator ::) of a type that was specified using a qualified-id

    In your case, typename MyType_OutArg<T>::type will not participate in type deduction, and T is not known from elsewhere, thus this template function is ignored.

    0 讨论(0)
提交回复
热议问题