Template default arguments

前端 未结 4 1601
耶瑟儿~
耶瑟儿~ 2020-11-29 17:19

If I am allowed to do the following:

template 
class Foo{
};

Why am I not allowed to do the following in main?

4条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-29 18:14

    With C++17, you can indeed.

    This feature is called class template argument deduction and add more flexibility to the way you can declare variables of templated types.

    So,

    template 
    class Foo{};
    
    int main() {
        Foo f;
    }
    

    is now legal C++ code.

提交回复
热议问题