overload vs default parameters in c++ standard

前端 未结 1 1629
星月不相逢
星月不相逢 2021-02-14 06:55

I was reading another question, and it got me thinking. Often the standard specifies functions which have default parameters in their descriptions. Does the standard allow writi

1条回答
  •  鱼传尺愫
    2021-02-14 07:08

    Could a conforming implementation of the standard library implement this instead as two functions like this?

    Yes. The C++ Standard (C++03 17.4.4.4/2-3) says:

    An implementation can declare additional non-virtual member function signatures within a [Standard Library] class:

    -- by adding arguments with default values to a member function signature; the same latitude does not extend to the implementation of virtual or global or non-member functions, however.

    -- by replacing a member function signature with default values by two or more member function signatures with equivalent behavior;

    -- by adding a member function signature for a member function name.

    A call to a member function signature described in the C + + Standard library behaves the same as if the implementation declares no additional member function signatures

    0 讨论(0)
提交回复
热议问题