This is a sample code for memory mapped file share.
The mapped_region is d class that is responsible for it
Now me before digging in deep I cant follow why such declaration are used. can any one please explain this to me ?
class mapped_region
{
// Non-copyable
mapped_region(const mapped_region &);
// Non-assignable
mapped_region &operator=(const mapped_region &);
public:
typedef /*implementation-defined*/ offset_t;
typedef /*implementation-defined*/ accessmode_t;
static const accessmode_t invalid_mode;
static const accessmode_t read_only;
static const accessmode_t read_write;
static const accessmode_t copy_on_write;
mapped_region();
mapped_region( const memory_mappable & mappable
, accessmode_t mode
, offset_t mappable_offset
, std::size_t size = 0
, const void * address = 0);
mapped_region(mapped_region &&other);
std::size_t get_size() const;
void* get_address() const;
offset_t get_offset() const;
accessmode_t get_mode() const;
void flush(std::size_t region_offset = 0, std::size_t numbytes = 0);
void swap(mapped_region &other);
~mapped_region();
};
In this example the
// Non-copyable
mapped_region(const mapped_region &);
what does that mean ?
Yes, it is possible to have a constructor with parameter name same as class.
Two situations are possible:
In your code:
represents a Copy Constructor, while:
represents a Move Constructor
A copy constructor is used to create copies of your class object. Whenever you pass the class object as function argument by value or a copy of your class object is needed then the compiler calls the copy constructor to create this object.
If you want to restrict the users of your class from making copies of your class object then you declare copying functions(copy constructor & copy assignment operator
=) asprivate, and this is what your code does in this case it restricts users of your code from creating any copies of your classmapped_region. Note that the default access specifier for an class isprivate.Since your code declares a Move constructor, I assume you are using C++11 and hence a better way to achieve the desired functionality here is to use explicitly deleting special member functions provided in C++11.
For Eg: