Archive
const Functions
When you are writing class definitions, remember to make member functions const where appropriate:
class foo {
// etc
public:
// etc
void print() const; // <--- const member function
// etc
};
If a member function that doesn’t modify it’s class fails to declare itself as const in this way then the compiler won’t let you call it from a const instance of the class. Of course, make sure you don’t get overzealous and mark as const member functions which do in fact modify the class in some way.
And you have to be careful with the meaning of ‘modify the class’. For example, suppose your class has a file stream and you write to it, then you are modifying the file stream and hence the class.
Tutorials Overhall
I’m currently restructuring the Tutorials section on this site. Feel free to head over there now to take a look at the new arrangement. Once my exams are over, you can expect many more tutorials in the current categories, and perhaps I’ll add others.
If you have any requests for tutorial categories or particular tutorials, please do let me know.
