Default template parameters with forward declaration

后端 未结 4 1524
太阳男子
太阳男子 2020-12-25 14:35

Is it possible to forward declare a class that uses default arguments without specifying or knowing those arguments?

For example, I would like to declare a boo

4条回答
  •  轮回少年
    2020-12-25 14:58

    Yes. Default template arguments may be specified any time, anywhere, so long as the declarations don't conflict with each other. They are ultimately merged together from the various declarations.

    Even this is legal:

    template< class A, class B, class C = long >
    class X;
    
    template< class A, class B = int, class C >
    class X;
    
    template< class A = short, class B, class C >
    class X { };
    

    A similar example is given in §14.1/10. According to that paragraph, function default arguments behave similarly.

    Good luck on getting the forward declaration to behave itself and not barf on everything!

提交回复
热议问题