4 ms·
You can overload on const in C++, so int a(foo b) and int a(const foo b) can coexist. We used this in Qt 2.0, there were a few cases where we could get signific
by Arnt 10y ago
You can overload on const in C++, so int a(foo b) and int a(const foo b) can coexist. We used this in Qt 2.0, there were a few cases where we could get significantly more oomph if we knew the argument was const.
Ff a function takes a struct (or class) as argument can calls otherfunction(foo.bar), then the constness of foo's bar field matters. The same might apply to fields of this.
- wfunction 10y agoNobody said it doesn't "matter" whether you put const. I was saying it's not worthwhile.
- pontobart 10y agoYou cannot overload on the const. If you try to define both int a(int b) and int a(const int b) the compiler will complain about a redefinition. You can declare the function using int a(int b) in the header and then define it via int a(const int b).