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

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


这两个功能是Juste定义和构造函数

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


计算表

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

最佳答案

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

#ifndef GtkwidgetDef_h
#define GtkwidgetDef_h

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

#endif

10-08 00:47