Hello people, I need an example and explination of the const keyword used in method signatures. I'm using a really, crappy book and i don't understand what they are trying to say. Thanks!
Printable View
Hello people, I need an example and explination of the const keyword used in method signatures. I'm using a really, crappy book and i don't understand what they are trying to say. Thanks!
It means it does not change values.
That's just something quick I threw together to show you. There might be some syntax errors.Code:
class foo
{public:
int returnint() const;//doesn't change the value of it
void setint(int number);
private:
int data=0;
}
int returnint() const
{ return data;}
void setint(int number)
{ data=number}