Const before function

 

Good morning

Can someone explain me what the const before a function does?

bool ReadOnly(void)     const { return(m_read_only); }          //with const
bool ReadOnly(void)           { return(m_read_only); }          //without const


does it make a difference if the function returns a fucntion or simple a variable?

string Text(void)       const { return(m_edit.Description()); }
string Text(void)             { return(m_edit.Description()); }


I have never used const with functions till now.

But in the mql4 includes it's used a lot.

I'm just curious and want to learn more :)

 
  1. Irrelevant for functions. Only applies to class methods.
  2. It means the method does not modify the object. If you have a constant reference or pointer, you can only call constant methods.
 
thank you very much :)
Reason: