【问题标题】:redefinition of "class GtkwidgetDef"重新定义“类 GtkwidgetDef”
【发布时间】:2012-01-24 11:36:47
【问题描述】:

我真的不知道为什么我有这个重新定义错误

GtkwidgetDef.h

#include <gtk/gtk.h>
class GtkwidgetDef
{
public:
    GtkWidget* display;
    GtkwidgetDef(GtkButton* button);
};

GtkwidgetDef.cpp

#include "GtkwidgetDef.h"
extern "C" GtkWidget* lookup_widget(GtkWidget* widget, const gchar* widgetName);

GtkwidgetDef::GtkwidgetDef(GtkButton* button){
display = lookup_widget(GTK_WIDGET(button), "display");
}

这两个函数只是定义和构造函数

MesFonctions.cpp

#include "MesFonctions.h"
#include <math.h>
string str;
gchar str1[9] = "";

void showText(GtkwidgetDef widgets, gchar* label)
{
gtk_entry_set_text(GTK_ENTRY(widgets->display), label);
}
.........

CALCU.h

#include <gtk/gtk.h>
typedef enum Event{ SEVEN_CLICKED, PLUS_CLICKED, VALIDE } Event;

int processEvent(Event e, GtkButton* button);

CALCU.cpp

#include "CALCU.h"
#include "MesFonctions.h"
#include "GtkwidgetDef.h"

int processEvent(Event e, GtkButton* button)
{
//GtkwidgetDef* widgets = new GtkwidgetDef();   
//label = gtk_button_get_label(button);
GtkwidgetDef widgets(button);
gchar* label;
strcpy(label, gtk_button_get_label(button));

string s;
switch(e)
{
    case SEVEN_CLICKED:
        //showText(*widgets, label);
        showText(widgets, label);
        s = "7";
        pushValue(s);
        break;
    case PLUS_CLICKED:
        //showText(*widgets, label);
        showText(widgets, label);
        s = "+";
        pushValue(s);
        break;
    case VALIDE:
        showResult();
        break;
}
}

我想知道我是否在这行 GtkwidgetDef widgets(button); 中犯了错误;

【问题讨论】:

  • 你能把你的"MesFonctions.h"文件也显示一下吗?

标签: c++ gtk redefinition


【解决方案1】:

我认为你看到这个的原因是你在某个时候包含了两次GtkwidgetDef.h:一次是直接的,一次是间接的。您可能需要在标题中添加include guard

#ifndef GtkwidgetDef_h
#define GtkwidgetDef_h

#include <gtk/gtk.h>
class GtkwidgetDef
{
public:
    GtkWidget* display;
    GtkwidgetDef(GtkButton* button);
};

#endif

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多