What is the difference between `void f1 (const Class & c)` and `void f2 (class const & c)`?

What is the difference between these functions below (Look at the const keyword)?

 void f1(const Class &c) 

and

 void f2(Class const &c) 
+4
source share
4 answers

There is no difference. Two versions are interchangeable.

+5
source

There is no difference between const Class& and Class const& ; Similarly, there is no difference between const Class* and Class const* . Both indicate a reference / pointer to a constant instance of Class .

However, Class* const is a completely different beast. This is a constant pointer to a non-const Class instance.

+5
source

(pedantic answer):

The difference is the name.

The name f1 will be different from f2 - even after mangling

The signatures are exactly the same, so otherwise there would be no difference

+4
source

They are not at all different. See paragraphs 18.6 and 18.8 in on this page for details .

+2
source

All Articles