Why is template parameter pack used in a function argument type as its template argument list not able to be explicit specified

前端 未结 5 621
失恋的感觉
失恋的感觉 2020-12-28 12:55

I have the following piece of code:

template 
struct AAA{};

template
void f(AAA *) {}

int          


        
5条回答
  •  天涯浪人
    2020-12-28 13:03

    I want to add another solution that invokes the {} notion

    template 
    struct AAA{};
    
    template
    void f(AAA *) {}
    
    int main() {
        f({});
    }
    

    When the argument is {}, deduction for the parameter is disabled (nondeduced context), so there will be no mismatch and the parameter initialization actually produces a null pointer aswell.

提交回复
热议问题