首页 > 解决方案 > 在 stroustrup 的 ppp2 示例中使用 FLTK 的窗口图形错误

问题描述

我收到了这个错误:

C2664 'void Graph_lib::Widget::attach(Window &)':无法将参数 1 从 'Graph_lib::Window' 转换为 'Window &'

这是一些 Window.h 代码

namespace Graph_lib {

class Shape;    // "forward declare" Shape
class Widget;

class Window : public Fl_Window {

....

和发生错误的 Window.cpp 代码

namespace Graph_lib {

....

void Window::attach(Widget& w)
{
    begin();            // FTLK: begin attaching new Fl_Wigets to this window

    **// I got error from this function**
    w.attach(*this);    // let the Widget create its Fl_Wigits
    end();              // FTLK: stop attaching new Fl_Wigets to this window
}

....

和 GUI.h 代码,它有 Widget 类

namespace Graph_lib {

....

class Widget {

....

virtual void attach(Window&) = 0;

....

我试图转换并制作一个变量,但它都是一样的。

Window& win = *this;
Graph_lib::Window& win = *this;
w.attach(static_cast<Window&>(*this));
w.attach(dynamic_cast<Window&>(*this));

我该怎么办?

标签: c++windowfltk

解决方案


推荐阅读