От: | Marty | https://www.youtube.com/channel/UChp5PpQ6T4-93HbNF-8vSYg | |
Дата: | 15.11.18 22:30 | ||
Оценка: |
// SPL sim
struct RawDeviceStruct
{
unsigned reg1;
}; // struct RawDeviceStruct
typedef RawDeviceStruct* RawDevice;
RawDevice DEV1 = (RawDevice)0x01;
// End of SPL sim
struct DeviceConfig
{
RawDevice device;
unsigned pin;
};
class Device
{
private:
Device(); // = delete
Device( const Device &d ); // = delete
public:
//Device() = delete;
//Device( const Device &d ) = delete;
// Err2
Device( RawDevice d, unsigned p )
: m_cfg()
{
m_cfg.device = d;
m_cfg.pin = p;
}
Device( const DeviceConfig &cfg )
: m_cfg(cfg)
{}
void operator=( const DeviceConfig &cfg )
{
m_cfg = cfg;
}
protected:
DeviceConfig m_cfg;
}; // class Device
int main()
{
static volatile Device device1( { DEV1, 4 } );
static volatile Device device2 = { DEV1, 4 }; // Err1
}
structs.cpp(66): error: #289: no instance of constructor "Device::Device" matches the argument list
argument types are: (RawDevice, int)
static volatile Device device2 = { DEV1, 4 }; // Err1
structs.cpp(65): error: #309: more than one instance of constructor "Device::Device" matches the argument list:
function "Device::Device(const Device &)"
function "Device::Device(const DeviceConfig &)"
argument types are: ({...})
static volatile Device device1( { DEV1, 4 } );
От: | Constructor | ||
Дата: | 16.11.18 06:54 | ||
Оценка: | +1 |
static volatile Device device2 = {DEV1, 4};
static volatile Device device2 = {{DEV1, 4}};