digitalmars.D.learn - function without "this" cannot be const?
- Shriramana Sharma (7/7) Dec 20 2015 I'm trying to interface to a C function:
- Jakob Ovrum (6/12) Dec 20 2015 Change it to:
- Basile B. (9/15) Dec 20 2015 without the parens, 'const' means that the function doesn't
- Shriramana Sharma (4/7) Dec 20 2015 Thank you people.
I'm trying to interface to a C function: extern(C) const char * textAttrN(const char * specString, size_t n); and getting the error: Error: function <src>.textAttrN without 'this' cannot be const Please advise as to what I'm doing wrong?! :-( --
Dec 20 2015
On Monday, 21 December 2015 at 02:03:14 UTC, Shriramana Sharma wrote:I'm trying to interface to a C function: extern(C) const char * textAttrN(const char * specString, size_t n); and getting the error: Error: function <src>.textAttrN without 'this' cannot be const Please advise as to what I'm doing wrong?! :-(Change it to: extern(C) const(char)* textAttrN(const char * specString, size_t n); ^ ^
Dec 20 2015
On Monday, 21 December 2015 at 02:03:14 UTC, Shriramana Sharma wrote:I'm trying to interface to a C function: extern(C) const char * textAttrN(const char * specString, size_t n); and getting the error: Error: function <src>.textAttrN without 'this' cannot be const Please advise as to what I'm doing wrong?! :-(without the parens, 'const' means that the function doesn't mutate the state of the object or of the struct it's declared in. So it's meaningless for a global function. To avoid the confusion, take the habit to put 'const' at the right of the function declaration when it's related to a member function and only to the left when it's related to the type, and then to the left <=> always with parens.
Dec 20 2015
Basile B. wrote:without the parens, 'const' means that the function doesn't mutate the state of the object or of the struct it's declared in. So it's meaningless for a global function.Thank you people. --
Dec 20 2015