Not related to the issue, but you have a SensorType from the class Sensor . Maybe it makes sense to make the SensorType part of the Sensor class and pass it to the constructor? Somehow, for example:
class Sensor { public: enum class Type{ DEFAULT = 0, ACCELEROMETER = 0, PROXYMETER = 1, TEMPERATURE = 2 }; explicit Sensor(const Type& type = Type::DEFAULT): m_unitOfMeasured{}, m_maximum{1}, m_minimum{0}, m_value{0.0}, m_type{type} { switch (m_type) { case Type::ACCELEROMETER: m_unitOfMeasured = "acceleration"; ... break; case Type::PROXYMETER: m_unitOfMeasured = "level"; ... break; case Type::TEMPERATURE: m_unitOfMeasured = "degree"; ... break; default: ... break; } } private: std::string m_unitOfMeasured; int m_maximum; int m_minimum; float m_value; Type m_type; }; class Date{}; class Device { public: Device(const Sensor::Type& sensorType = Sensor::Type::DEFAULT): m_sensor{sensorType}, m_date{}, m_placeBinding{} {} private: Sensor m_sensor; Date m_date; int m_placeBinding; };
UPD. Well then, something like this:
enum class SensorType{ DEFAULT = 0, UNKNOW = 0, ACCELEROMETER = 1, PROXYMETER = 2, TEMPERATURE = 3 }; class Sensor { public: Sensor(const SensorType& type = SensorType::DEFAULT): m_unitOfMeasured{}, m_maximum{1}, m_minimum{0}, m_value{0.0}, m_type{type} { switch (m_type) { case SensorType::ACCELEROMETER: m_unitOfMeasured = "acceleration"; break; case SensorType::PROXYMETER: m_unitOfMeasured = "level"; break; case SensorType::TEMPERATURE: m_unitOfMeasured = "degree"; break; default: break; } } private: std::string m_unitOfMeasured; int m_maximum; int m_minimum; float m_value; SensorType m_type; }; class Date{}; class Device { public: Device(const Date& date, const int placeBinding, const SensorType& sensorType= SensorType::DEFAULT): m_type{sensorType}, m_sensor{sensorType}, m_date{date}, m_placeBinding{placeBinding} {} Device(const Device& other): m_type{other.m_type}, m_sensor{other.m_sensor}, m_date{other.m_date}, m_placeBinding{other.m_placeBinding} { } static Device createByUser(){ int n; std::cout << "choise 1, 2 or 3 type of sensor: " << std::endl; std::cout << "1. ACCELEROMETER" << std::endl; std::cout << "2. PROXYMETER" << std::endl; std::cout << "3. TEMPERATURE" << std::endl; std::cin >> n; if (n >= 1 && n <= 3){ return Device(Date(), 0, static_cast<SensorType>(n)); }else{ return Device(Date(), 0); } } private: SensorType m_type; Sensor m_sensor; Date m_date; int m_placeBinding; };