Implicit Template Parameters

后端 未结 7 938
佛祖请我去吃肉
佛祖请我去吃肉 2021-02-07 15:00

The following code generates a compile error in Xcode:

template 
struct Foo
{
    Foo(T Value)
    {
    }
};

int main()
{
    Foo MyFoo(123);         


        
相关标签:
7条回答
  • 2021-02-07 15:48

    What you are trying to do now works in C++ 17. Template parameters can be inferred in C++ 17.

    template <typename T>
    struct Foo
    {
        Foo(T Value)
        {
        }
    };
    
    int main()
    {
        Foo a(123);
        Foo b = 123;
        Foo c {123};
        return 0;
    }
    
    0 讨论(0)
提交回复
热议问题