Error: function `...` without `this` cannot be `const`
H. S. Teoh
hsteoh at quickfur.ath.cx
Wed Jun 30 18:29:22 UTC 2021
On Wed, Jun 30, 2021 at 05:47:05PM +0000, someone via Digitalmars-d-learn wrote:
[...]
> ```d
> public string getAmountSI(
> in float lnumAmount
> ) const {
[...]
> }
> ```
>
> I used to put all attributes BEFORE the function name which now I
> understand is completely wrong since they should follow the parameter
> declaration section because putting them before affects the function
> in other ways.
The `const` here is being applied to the implicit `this` parameter to
your function. If your function is not a member function (does not have
an implicit `this` parameter), then the attribute is meaningless.
T
--
Give me some fresh salted fish, please.
More information about the Digitalmars-d-learn
mailing list