WinLamb错误:非法成员初始化

时间:2018-09-10 21:47:12

标签: c++ c++11 winapi visual-studio-2017 c++14

我正在尝试学习如何使用WinLamb(一种用于Win32 API的轻量级现代C ++库),仅使用标头,并使用C ++ 11 lambda处理Windows消息。
我已经在Visual Studio 2017中创建了一个空的Win32项目,并按照Codeproject article顶部的示例添加了两个文件(与Github WinLamb页面相同)。 包含的唯一文件是<winlamb/window_main.h>
尝试编译时,出现以下错误(均为<winlamb/internals/window.h>的第45行):

C2614 wl::wli::window <wl::wli::w_thread_capable<LRESULT,0>>::_styler' illegal member initialization: 'styler' is not a base or member

C2512 'wl::wli::styler<wl::wli::window<wl::wli::w_thread_capable<LRESULT,0>>>': no appropriate default constructor available

此最小示例应用程序的整个代码包含两个文件:
My_Window.h

#pragma once
#include <winlamb/window_main.h>

class My_Window : public wl::window_main {
public:
    My_Window();
};

和My_Window.cpp

#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;
    });
}

在文件<winlamb/internals/window.h>上,我们注意到它包含以下标头:

#include "w_thread_capable.h"
#include "w_user_control.h"
#include "styler.h"

错误似乎与w_thread_capable类有关。 模板类w_thread_capable仅具有一个(受保护的)构造函数。我试图将其更改为公开,但出现了相同的错误。 这里出现错误的文件<winlamb/internals/window.h>的一部分:

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) { }
    };
// ...  
};

这是styler类的代码(文件:<winlamb/internals/styler.h>):

/**
 * 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

老实说,我无法理解此代码。
每个建议都值得赞赏。

1 个答案:

答案 0 :(得分:2)

修改from django.db import models # Create your models here. class IdCard(models.Model): emp_id = models.CharField(max_length=12) emp_name = models.CharField(max_length=40) emp_title = models.CharField(max_length=30) emp_telephone = models.CharField(max_length=12) emp_email = models.CharField(max_length=30) emp_generation = models.CharField(max_length=20) emp_status = models.CharField(max_length=20) def __str__(self): return self.emp_name <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Homepage</title> </head> <body> <h1>Identity Cards</h1> <div class="identitycards"> {% for cards in cards %} <div class="identitycard"> <p>{{ IdCard.emp_name }}</p> </div> {% endfor %} </div> </body> </html> 的定义,以在基本初始化程序中显式指定完整的类模板。

class _styler

winlamb/internals/window.h