www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - What is a mutable method?

reply "tcak" <tcak gmail.com> writes:
I know there is mutable variables, but what is a mutable method?

Error message says "mutable method 
project.mariadb.connector.ver2p1.resultset.ResultSetColumn.info 
is not callable using a const object".
May 22 2015
next sibling parent "FreeSlave" <freeslave93 gmail.com> writes:
On Friday, 22 May 2015 at 12:12:46 UTC, tcak wrote:
 I know there is mutable variables, but what is a mutable method?

 Error message says "mutable method 
 project.mariadb.connector.ver2p1.resultset.ResultSetColumn.info 
 is not callable using a const object".
The method that can change the state of the object. This kind of error says that you try to call non-const method on const object, which is prohibited. You can call only the methods marked as const on the const object.
May 22 2015
prev sibling next sibling parent Steven Schveighoffer <schveiguy yahoo.com> writes:
On 5/22/15 8:12 AM, tcak wrote:
 I know there is mutable variables, but what is a mutable method?

 Error message says "mutable method
 project.mariadb.connector.ver2p1.resultset.ResultSetColumn.info is not
 callable using a const object".
English grammar nit: I would say mutating instead of mutable. -Steve
May 22 2015
prev sibling parent Jonathan M Davis via Digitalmars-d-learn writes:
On Friday, May 22, 2015 12:12:45 tcak via Digitalmars-d-learn wrote:
 I know there is mutable variables, but what is a mutable method?

 Error message says "mutable method
 project.mariadb.connector.ver2p1.resultset.ResultSetColumn.info
 is not callable using a const object".
It's a method / member function which is not const or immutable. e.g. struct MyStruct { void foo() {} // This method is mutable void bar() const {} void baz() immutable {} } What it's really indicating is the constness of the object's this point is inside the function. So, you can only call a mutable method on a mutable object, because otherwise, you'd be converting a const or immutable reference or pointer to mutable, which would violate the type system. mutable and immutable can be converted to const, but mutable and const can't be converted to immutable, and const and immutable can't be converted to mutable. So, in your case, it sounds like you're trying to call a mutable method on a const object, which won't work. The method needs to be const, since the object is const. - Jonathan M Davis
May 22 2015