WinLamb错误:非法的成员初始化 我试图学习如何使用Win32 API的一个轻量级的现代C++库,只使用C++ 11 LAMBDAS来处理Windows消息。 我在Visual Studio 2017中创建了一个空的Win32项目,并在顶部添加了两个文件,如示例所示(与Github WinLamb页面相同)。 唯一包含的文件是 尝试编译时,我收到以下错误(都在的第45行):
WinLamb错误:非法的成员初始化 我试图学习如何使用Win32 API的一个轻量级的现代C++库,只使用C++ 11 LAMBDAS来处理Windows消息。 我在Visual Studio 2017中创建了一个空的Win32项目,并在顶部添加了两个文件,如示例所示(与Github WinLamb页面相同)。 唯一包含的文件是 尝试编译时,我收到以下错误(都在的第45行):,c++,c++11,winapi,visual-studio-2017,c++14,C++,C++11,Winapi,Visual Studio 2017,C++14,C2614 wl::wli::window::_styler'非法成员初始化:'styler'不是基或成员 和 C2512'wl::wli::styler':没有合适的默认构造函数可用 此最小示例应用程序的整个代码由两个文件组成: 我的窗口.h #pragma once #include <winlamb/window_main.h> class My_Window : public wl::window_main { public: My_Window(); }; 查看
C2614 wl::wli::window::_styler'非法成员初始化:'styler'不是基或成员
和
C2512'wl::wli::styler':没有合适的默认构造函数可用
此最小示例应用程序的整个代码由两个文件组成:
我的窗口.h
#pragma once
#include <winlamb/window_main.h>
class My_Window : public wl::window_main {
public:
My_Window();
};
查看文件
,我们注意到它包括以下标题:#include "w_thread_capable.h"
#include "w_user_control.h"
#include "styler.h"
这些错误似乎与支持线程的w\u类有关。
模板类w\u thread\u capable
只有一个(受保护的)构造函数。我试着把它改成public,但我也犯了同样的错误。
这里是文件
的一部分,在这里我得到了错误:
template<typename baseT>
class window : public baseT {
// ...
private:
class _styler final : public wli::styler<window> {
public:
// error here:
explicit _styler(window* pWindow) noexcept : styler(pWindow) { }
};
// ...
};
我真的不能理解这个代码
非常感谢您的建议。在winlamb/internals/window.h
中修改class\u styler
的定义,以明确指定基本初始值设定项中的完整类模板
class _styler final : public wli::styler<window> {
public:
// Error in VC 2017
//explicit _styler(window* pWindow) noexcept : styler(pWindow) { }
// No errors
explicit _styler(window* pWindow) noexcept : wli::styler<window>(pWindow) { }
};
class\u styler final:public wli::styler{
公众:
//VC 2017中的错误
//显式_styler(window*pWindow)noexcept:styler(pWindow){
//没有错误
显式_styler(window*pWindow)noexcept:wli::styler(pWindow){
};
或
class\u样式器最终版本:公共样式器{
公众:
显式_styler(window*pWindow)noexcept:styler(pWindow){
};
请直接在您的问题中添加相关代码,并且仅使用链接作为支持参考,因为链接可能会发生变化,我们希望问题在将来也会有用。谢谢您的代码仍然很长,您能否尝试将其缩减到一个演示问题的最小示例?我们需要查看您的模板实例化。同样重要的是,由于Visual Studio在C++17法规遵从性方面做了重大更改,您使用的是Visual Studio的哪个版本?我使用的是Visual Studio 2017社区版15.8.3-OS:Windows 10 Pro x64-Windows SDK版本:10.0.17134.0(我也尝试了10.0.14393.0和10.0.16299.0,结果相同)-为x86平台构建的测试应用程序尝试在显式样式器(window*pWindow)noexcept:styler(pWindow){}
->显式样式器(window*pWindow)noexcept:wli::styler(pWindow){}
中添加。在winlab/button.h
中有一行explicit_styler(button*pButton)noexcept:styler(pButton){}
。这里还必须添加模板参数explicit _styler(button*pButton)noexcept:styler(pButton){}
。在这种情况下,只需重复基类类型。
/**
* 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 <Windows.h>
namespace wl {
namespace wli {
// Wraps window style changes with Get/SetWindowLongPtr, and allows custom methods.
template<typename wndT>
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<LONG_PTR>(styleFlags);
} else {
curFlags &= ~static_cast<LONG_PTR>(styleFlags);
}
SetWindowLongPtrW(this->_wnd.hwnd(), isEx ? GWL_EXSTYLE : GWL_STYLE, curFlags);
return this->_wnd;
}
};
}//namespace wli
}//namespace wl
class _styler final : public wli::styler<window> {
public:
// Error in VC 2017
//explicit _styler(window* pWindow) noexcept : styler(pWindow) { }
// No errors
explicit _styler(window* pWindow) noexcept : wli::styler<window>(pWindow) { }
};
class _styler final : public styler<window> {
public:
explicit _styler(window* pWindow) noexcept : styler<window>(pWindow) { }
};