Я создал пустой проект Win32 в Visual Studio 2017 и добавил два файла, как в примере на вершине статьи CodeProject (то же самое из страницы Github Winlamb). .
Попытка компилировать, я получаю следующие ошибки (оба в строке 45 из ):
Код: Выделить всё
C2614 wl::wli::window ::_styler' illegal member initialization: 'styler' is not a base or member < /code>
и
C2512 'wl::wli::styler': no appropriate default constructor available< /code>
< /p>
Весь код для этого минимального приложения состоит из двух файлов:
my_window.h
< /p>
#pragma once
#include
class My_Window : public wl::window_main {
public:
My_Window();
};
< /code>
и my_window.cpp < /p>
#include "My_Window.h"
RUN(My_Window) // optional, generate WinMain call and instantiate My_Window
My_Window::My_Window()
{
setup.wndClassEx.lpszClassName = L"SOME_CLASS_NAME"; // class name to be registered
setup.title = L"This is my window";
setup.style |= WS_MINIMIZEBOX;
on_message(WM_CREATE, [this](wl::wm::create p)->LRESULT
{
set_text(L"A new title for the window");
return 0;
});
on_message(WM_LBUTTONDOWN, [](wl::wm::lbuttondown p)->LRESULT
{
bool isCtrlDown = p.has_ctrl();
long xPos = p.pos().x;
return 0;
});
}
< /code>
Просматривать файл < /code> мы отмечаем, что он включает в себя следующие заголовки:
< /p>
#include "w_thread_capable.h"
#include "w_user_control.h"
#include "styler.h"
< /code>
Ошибки, кажется, связаны с классом w_thread_capable < /code>.
Шаблонный класс W_THREAD_CAPABLE < /code> имеет только один (защищенный) конструктор. Я попытался изменить его на публику, но я получил те же ошибки.
здесь часть файла < /code>, где я получаю ошибку:
< /p>
template
class window : public baseT {
// ...
private:
class _styler final : public wli::styler {
public:
// error here:
explicit _styler(window* pWindow) noexcept : styler(pWindow) { }
};
// ...
};
/**
* Part of WinLamb - Win32 API Lambda Library
* https://github.com/rodrigocfd/winlamb
* Copyright 2017-present Rodrigo Cesar de Freitas Dias
* This library is released under the MIT License
*/
#pragma once
#include
namespace wl {
namespace wli {
// Wraps window style changes with Get/SetWindowLongPtr, and allows custom methods.
template
class styler {
private:
wndT& _wnd;
protected:
explicit styler(wndT* target) noexcept : _wnd(*target) { }
public:
styler(const styler&) = delete;
styler& operator=(const styler&) = delete; // non-copyable, non-movable
protected:
HWND hwnd() const noexcept { return this->_wnd.hwnd(); }
wndT& target() const noexcept { return this->_wnd; }
public:
wndT& set_style(bool addStyle, DWORD styleFlags) noexcept {
return this->_change_style_flags(false, addStyle, styleFlags);
}
wndT& set_style_ex(bool addStyle, DWORD styleFlags) noexcept {
return this->_change_style_flags(true, addStyle, styleFlags);
}
bool has_style(DWORD styleFlags) const noexcept {
return (GetWindowLongPtrW(this->_wnd.hwnd(), GWL_STYLE) & styleFlags) != 0;
}
bool has_style_ex(DWORD styleFlags) const noexcept {
return (GetWindowLongPtrW(this->_wnd.hwnd(), GWL_EXSTYLE) & styleFlags) != 0;
}
private:
wndT& _change_style_flags(bool isEx, bool addStyle, DWORD styleFlags) noexcept {
LONG_PTR curFlags = GetWindowLongPtrW(this->_wnd.hwnd(), isEx ? GWL_EXSTYLE : GWL_STYLE);
if (addStyle) {
curFlags |= static_cast(styleFlags);
} else {
curFlags &= ~static_cast(styleFlags);
}
SetWindowLongPtrW(this->_wnd.hwnd(), isEx ? GWL_EXSTYLE : GWL_STYLE, curFlags);
return this->_wnd;
}
};
}//namespace wli
}//namespace wl
< /code>
Я, честно говоря, не могу понять этот код.
Каждое предложение ценится. < /p>
Подробнее здесь: https://stackoverflow.com/questions/522 ... ialization