I’m trying to understand the following piece of code:
lock_server::lock_server(class rsm *_rsm)
{
//code
}
I know that this is the constructor for the class, but I don’t understand its argument.
I’m guessing that this is a pointer (with name _rsm) that points to a class? Does that make sense? Where can I find documentation about this?
The keyword
classbefore the termrsmis not necessary in C++ (unlike in C where you must specify the wordstruct).However that doesn’t mean it is forbidden and whoever wrote that felt it was good style, albeit it’s intuitive that
rsmis a type of some sort (not necessarily a class, could be a typedef to a class)The purpose of that constructor is to construct an object of type
lock_serverwith a pointer to a modifiablersmobject. My guess is thatrsmhas some kind oflockmethod which will be called from the constructor, and anunlockmethod which will be called from the destructor.The purpose of the
lock_serverclass is to implement what is called RAII: a stupid acronym but in real life it means automated resource management – when the object leaves scope the destructor kicks in which releases the resource it is holding, in this case a lock to thersmobject.