devxlogo

Const and Reference Data Members Must be Initialized

Const and Reference Data Members Must be Initialized

A class may have const and reference data members. These members must be explicitly initialized by a member-initialization list:

 class Allocator{private:  const int chunk_size;   const string & serialization_path; // file into which an object can be serialized public:  Allocator(int size, const string& path) : chunk_size(size), serialization_path (path){}};

devx-admin

Share the Post: