Search code examples
referenceconst-correctness

Any difference between const Class& and Class const&?


Is there any difference between that expressions :

const Class&
Class const&

for example, when those are parameters of function ?


Solution

  • There is no difference between const Class& and Class const&; similarly here is no difference between const Class* and Class const*.

    And so,

    void f1 (const Class& c)
    

    and

    void f1 (Class const& c)
    

    are interchangeable with no difference.

    Both versions denote a reference to a constant Class instance and can be used interchangeably.