   This didn't make sense to me: "void function ( ) cont". Anyone care to explain.
  'Aight, so I came across this format yesterday:void function() const{//Blahbly-blahbly-blah}I googled it and I came across a few topics related to it but I couldn't make much sense of it. I was hoping someone could share some enlightenment. Thanks. :]   
  This is a member function of some class. 'const' in that position guarantees that the function will not modify the this-object.   ;Quote:Original post by ZahlmanThis is a member function of some class. 'const' in that position guarantees that the function will not modify the this-object.Yeah, it was a member function. Would it really be necessary to not modify the this-object? Could you simply not include the this-object? I'm not entirely sure why it is important. ( I'm sure it is or the creators wouldn't have put it there to begin with :p )Thanks Zahlman.   ;Quote:Original post by PCNYeah, it was a member function. Would it really be necessary to not modify the this-object? Could you simply not include the this-object? I'm not entirely sure why it is important. ( I'm sure it is or the creators wouldn't have put it there to begin with :p )In C++, member functions have an implicit this pointer passed to them every time they are called. This pointer points to the current object that the function is a member of. When you access a member variable in a member function, you are implicity accessing this->VariableName. As such, any function which modifies the value of a member variable changes the state of the this-object, and is therefore non-const.By appending a const qualifier to a member function, you are saying that the object pointed at by the this pointer does not change. This can help eliminate logic errors in a program. See: const correctness.   ;Quote:Original post by PCNQuote:Original post by ZahlmanThis is a member function of some class. 'const' in that position guarantees that the function will not modify the this-object.Yeah, it was a member function. Would it really be necessary to not modify the this-object? Could you simply not include the this-object? I'm not entirely sure why it is important. ( I'm sure it is or the creators wouldn't have put it there to begin with :p )Thanks Zahlman.The this object is implied, since it's a member function. Perhaps a simple example will help clarify:class Foo{    int data;    // This member function is marked as "const", meaning "I promise not to modify this object"    int Bar() const    {   // data = 0; // This is illegal, since it modifies something the object   return 5;    }    // not const    void Baz()    {   data = 0; // fine    }};  The const correctness article is one of the many things I came across via google. :]Thanks guys. I understand it now. I knew about the implied "this" but I didn't understand what made "void func() const" different from "void func(), but I know now. Thanks.   