When defining a member function out-of-line, which qualifiers must appear in the declaration / definition / both?

后端 未结 3 754
别那么骄傲
别那么骄傲 2021-01-20 23:50

I am almost sure this has been asked before. Unfortunately, my C++ has become so rusty that I don\'t even know what to search for.

Is there an easy-to-remember rule of t

3条回答
  •  南方客
    南方客 (楼主)
    2021-01-21 00:28

    General rule is that when removing a qualifier produces a different function overload, that qualifier must appear in both places. All other qualifiers stay in the declaration.

    The three qualifiers that must appear in both places are const and the two kinds of reference qualifiers, which appear in the C++11 standard:

    void foo() const;
    void foo() &;
    void foo() &&;
    

    All other qualifiers stay in the declaration.

提交回复
热议问题