gpt4 book ai didi

c++ - 重新定义 "class GtkwidgetDef"

转载 作者:行者123 更新时间:2023-11-28 08:11:19 26 4
gpt4 key购买 nike

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

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

计算器.h

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

int processEvent(Event e, GtkButton* button);

计算器.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

关于c++ - 重新定义 "class GtkwidgetDef",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8986166/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com