Compilation Error on Recursive Variadic Template Function

后端 未结 2 1876
慢半拍i
慢半拍i 2020-12-16 03:05

I\'ve prepared a simple variadic template test in Code::Blocks, but I\'m getting an error:

No matching function for call to \'OutputSizes()\'

2条回答
  •  囚心锁ツ
    2020-12-16 03:33

    Here's how you disambiguate the base case:

    #include 
    #include 
    
    template 
    void OutputSizes()
    {
        std::cout << typeid(FirstDatatype).name() << ": " << sizeof(FirstDatatype) << std::endl;
    }
    
    template 
    void OutputSizes()
    {
        OutputSizes()
        OutputSizes();
    }
    
    int main()
    {
        OutputSizes();
    }
    

提交回复
热议问题