Ошибку-то покажите. Я могу максимум добавить, что операторы без rvalue в контейнере это friend контейнера и что в класс с полем i это:
struct SS {
int i[5] = { 1,2,3,4,5 };
};
error C2666: "dte_utils::operator +": перегруженные функции имеют похожие преобразования?
умный указатель мне нужен для того, чтобы отслеживать, является ли функция выгруженной
DWORD ComIface::write(byte* data, int count) {
DWORD NumOfWritten, status;
OVERLAPPED overlap = { 0 };
overlap.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (!overlap.hEvent) {
printf("CreateEvent failed with error %d.\n", GetLastError());
return 0;
}
if (!WriteFile(port_handle, data, count, &NumOfWritten, &overlap)) {
status = GetLastError();
if (status != ERROR_IO_PENDING) {
printf("WriteFile failed with error %d.\n", status);
CloseHandle(overlap.hEvent);
return 0;
}
status = WaitForSingleObject(overlap.hEvent, read_delay);
if (status == WAIT_ABANDONED || status == WAIT_FAILED) {
printf("WaitForSingleObject failed with error %d.\n", GetLastError());
}
if (!GetOverlappedResult(port_handle, &overlap, &NumOfWritten, TRUE)) {
printf("GetOverlappedResult failed with error %d.\n", GetLastError());
}
}
CloseHandle(overlap.hEvent);
return NumOfWritten;
}
DWORD ComIface::read(byte* buffer, int size) {
DWORD NumberOfBytesReaded = 0, status = 0;
OVERLAPPED overlap = { 0 };
overlap.hEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
if (!overlap.hEvent) {
printf("CreateEvent failed with error %d.\n", GetLastError());
return 0;
}
if (!ReadFile(port_handle, buffer, size, NULL, &overlap)) {
status = GetLastError();
if (status != ERROR_IO_PENDING) {
printf("ReadFile failed with error %d.\n", status);
CloseHandle(overlap.hEvent);
return 0;
}
status = WaitForSingleObject(overlap.hEvent, read_delay);
if (status == WAIT_ABANDONED || status == WAIT_FAILED) {
printf("WaitForSingleObject failed with error %d.\n", GetLastError());
}
if (!GetOverlappedResult(port_handle, &overlap, &NumberOfBytesReaded, TRUE)) {
printf("GetOverlappedResult failed with error %d.\n", GetLastError());
}
}
CloseHandle(overlap.hEvent);
return NumberOfBytesReaded;
}
bool ComIface::open(int _port_num, bool log) {
//create port name
wchar_t strbuffer[11];
swprintf_s(strbuffer, 11, L"\\\\.\\COM%d", _port_num);
//create port handle
port_handle = CreateFileW(
strbuffer,
GENERIC_READ | GENERIC_WRITE,
0, //must be opened with exclusive-access
NULL, //default security attributes
OPEN_EXISTING, //must use OPEN_EXISTING
FILE_FLAG_OVERLAPPED, //async I/O
NULL //hTemplate must be NULL for comm devices
);
//check if handle is valid
if (port_handle == INVALID_HANDLE_VALUE) {
if (log) {
printf("CreateFileW failed with error %d.\n", GetLastError());
}
return false;
}
//set port settings
if (!SetCommState(port_handle, &dcb)) {
if (log) {
printf("SetCommState failed with error %d.\n", GetLastError());
}
close();
return false;
}
//set port timings
COMMTIMEOUTS timings{
10, /* Maximum time between read chars. */
10, /* Multiplier of characters. */
10, /* Constant in milliseconds. */
10, /* Multiplier of characters. */
10 /* Constant in milliseconds. */
};
SetCommTimeouts(port_handle, &timings);
PurgeComm(port_handle, PURGE_RXCLEAR | PURGE_TXCLEAR);
//set port state
port_num = _port_num;
return true;
}
это не значит, что ReadFile гарантированно завершиться синхронно