inout method is not callable using a const object

Jonathan Crapuchettes jcrapuchettes at gmail.com
Fri Sep 6 14:00:23 PDT 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.
> 
> Ali

Sorry 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


More information about the Digitalmars-d-learn mailing list