digitalmars.D.learn - inout method is not callable using a const object
- Jonathan Crapuchettes (19/19) Sep 06 2013 Can someone help me understand how to correct this error?
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (19/38) Sep 06 2013 I can reproduce it with this code:
- Jonathan Crapuchettes (12/59) Sep 06 2013 Sorry for not including the call site. Here is an example of the call:
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (5/7) Sep 06 2013 Unless Address is an alias of int, there is no matching opIndex overload...
- Jonathan Crapuchettes (5/17) Sep 06 2013 Thank you for your help. For some reason, no one else in the office
- =?UTF-8?B?QWxpIMOHZWhyZWxp?= (3/6) Sep 06 2013 http://d.puremagic.com/issues/show_bug.cgi?id=10982
Can someone help me understand how to correct this error? Error: inout method ...ValidSparseDataStore.opIndex is not callable using a const object The specific method is defined as: struct ValidSparseDataStore { inout(DataT*) opIndex(const Address addr) inout { if (auto node = findNode(addr)) return cast(inout)&(node.data); return null; } private ValidSparseNode* findNode(const Address ids) const { ... } } Thank you, JC
Sep 06 2013
On 09/06/2013 01:14 PM, Jonathan Crapuchettes wrote:Can someone help me understand how to correct this error? Error: inout method ...ValidSparseDataStore.opIndex is not callable using a const objectThat error is about opIndex but we don't see any code that makes that call.The specific method is defined as: struct ValidSparseDataStore { inout(DataT*) opIndex(const Address addr) inout { if (auto node = findNode(addr)) return cast(inout)&(node.data); return null; } private ValidSparseNode* findNode(const Address ids) const { ... } } Thank you, JCI can reproduce it with this code: struct S { void foo(int) inout {} } void main() { const s = S(); s.foo(42); // <-- works s.foo(); // <-- ERROR } Error: inout method deneme.S.foo is not callable using a const object I can't know whether this matches your case but the compiler should error about not finding a matching foo() overload instead of bringing the inout into the discussion. Ali
Sep 06 2013
On Fri, 06 Sep 2013 13:27:20 -0700, Ali Çehreli wrote:On 09/06/2013 01:14 PM, Jonathan Crapuchettes wrote: > Can someone help me understand how to correct this error? > > Error: inout method ...ValidSparseDataStore.opIndex is not callable > using a const object That error is about opIndex but we don't see any code that makes that call. > The specific method is defined as: > > struct ValidSparseDataStore { > inout(DataT*) opIndex(const Address addr) inout { > if (auto node = findNode(addr)) > return cast(inout)&(node.data); > > return null; > } > > private ValidSparseNode* findNode(const Address ids) const { > ... > } > } > > Thank you, > JC I can reproduce it with this code: struct S { void foo(int) inout {} } void main() { const s = S(); s.foo(42); // <-- works s.foo(); // <-- ERROR } Error: inout method deneme.S.foo is not callable using a const object I can't know whether this matches your case but the compiler should error about not finding a matching foo() overload instead of bringing the inout into the discussion. AliSorry for not including the call site. Here is an example of the call: void main() { auto store = ...; //add items to the storage const cStore = store; auto dp = cStore[16057]; //<-- ERROR } I can try to minimize the code to a working example if needed. Thank you, JC
Sep 06 2013
I think it is the same issue then. On 09/06/2013 02:00 PM, Jonathan Crapuchettes wrote:Unless Address is an alias of int, there is no matching opIndex overload for the following call:> inout(DataT*) opIndex(const Address addr) inout {auto dp = cStore[16057]; //<-- ERRORAli
Sep 06 2013
On Fri, 06 Sep 2013 14:08:19 -0700, Ali Çehreli wrote:I think it is the same issue then. On 09/06/2013 02:00 PM, Jonathan Crapuchettes wrote: >> > inout(DataT*) opIndex(const Address addr) inout { Unless Address is an alias of int, there is no matching opIndex overload for the following call: > auto dp = cStore[16057]; //<-- ERROR AliThank you for your help. For some reason, no one else in the office noticed that problem. In my code Address was something like TypeTuple! (int, char) and I was trying to call opIndex(int, int). Thank you again.
Sep 06 2013
On 09/06/2013 01:27 PM, Ali Çehreli wrote:the compiler should error about not finding a matching foo() overload instead of bringing the inout into the discussion.http://d.puremagic.com/issues/show_bug.cgi?id=10982 Ali
Sep 06 2013