inout method is not callable using a const object

Ali Çehreli acehreli at yahoo.com
Fri Sep 6 13:27:20 PDT 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 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



More information about the Digitalmars-d-learn mailing list