在项目中拥有自己的命名空间,我们希望使用gtkmm包含GUI。
// in a header file:
namespace project
{
// namespace "gui" is declared elsewhere
class gui::Config : Gtk::Window
{
protected:
Config();
private:
// various Gtk::Widget objects
void connect_signals();
};
}
一切正常直到我尝试实现此方法:
void Config::connect_signals()
{
m_notebook.signal_switch_page().connect(sigc::mem_fun(*this,&Config::on_notebook_switch_page));
m_button_save.signal_clicked().connect(sigc::mem_fun(*this,&Config::on_button_clicked_save));
m_button_close.signal_clicked().connect(sigc::mem_fun(*this,&Config::on_button_clicked_close));
}
然后我们使用pkg-config --cflags gtkmm-2.4
和pkg-config --libs gtkmm-2.4
编译Config.cpp。
编译器最终抛出以下消息:
In file included from /usr/include/sigc++-2.0/sigc++/signal_base.h:29:0,
from /usr/include/sigc++-2.0/sigc++/signal.h:8,
from /usr/include/sigc++-2.0/sigc++/sigc++.h:23,
from /usr/include/glibmm-2.4/glibmm/signalproxy.h:13,
from /usr/include/glibmm-2.4/glibmm/objectbase.h:23,
from /usr/include/glibmm-2.4/glibmm/wrap.h:26,
from /usr/include/glibmm-2.4/glibmm/containerhandle_shared.h:25,
from /usr/include/glibmm-2.4/glibmm/arrayhandle.h:23,
from /usr/include/glibmm-2.4/glibmm.h:83,
from /usr/include/gtkmm-2.4/gtkmm.h:87,
from include/libproject.h:12,
from include/gui/Config.h:4,
from src/gui/Config.cpp:1:
/usr/include/sigc++-2.0/sigc++/type_traits.h: In instantiation of ‘const bool sigc::is_base_and_derived<sigc::trackable, project::gui::Config>::value’:
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:1922:26: instantiated from ‘sigc::bound_mem_functor2<void, project::gui::Config, _GtkNotebookPage*, unsigned int>’
src/gui/Config.cpp:70:94: instantiated from here
/usr/include/sigc++-2.0/sigc++/type_traits.h:132:16: error: ‘sigc::trackable’ is an inaccessible base of ‘project::gui::Config’
In file included from /usr/include/sigc++-2.0/sigc++/adaptors/adaptor_trait.h:9:0,
from /usr/include/sigc++-2.0/sigc++/functors/slot.h:7,
from /usr/include/sigc++-2.0/sigc++/signal_base.h:31,
from /usr/include/sigc++-2.0/sigc++/signal.h:8,
from /usr/include/sigc++-2.0/sigc++/sigc++.h:23,
from /usr/include/glibmm-2.4/glibmm/signalproxy.h:13,
from /usr/include/glibmm-2.4/glibmm/objectbase.h:23,
from /usr/include/glibmm-2.4/glibmm/wrap.h:26,
from /usr/include/glibmm-2.4/glibmm/containerhandle_shared.h:25,
from /usr/include/glibmm-2.4/glibmm/arrayhandle.h:23,
from /usr/include/glibmm-2.4/glibmm.h:83,
from /usr/include/gtkmm-2.4/gtkmm.h:87,
from include/libproject.h:12,
from include/gui/Config.h:4,
from src/gui/Config.cpp:1:
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h: In instantiation of ‘sigc::bound_mem_functor2<void, project::gui::Config, _GtkNotebookPage*, unsigned int>’:
src/gui/Config.cpp:70:94: instantiated from here
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:1922:26: error: ‘sigc::is_base_and_derived<sigc::trackable, project::gui::Config>::value’ is not a valid template argument for type ‘bool’ because it is a non-constant expression
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h: In instantiation of ‘sigc::bound_mem_functor0<void, project::gui::Config>’:
src/gui/Config.cpp:72:95: instantiated from here
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:1792:26: error: ‘sigc::is_base_and_derived<sigc::trackable, project::gui::Config>::value’ is not a valid template argument for type ‘bool’ because it is a non-constant expression
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h: In constructor ‘sigc::bound_mem_functor2<T_return, T_obj, T_arg1, T_arg2>::bound_mem_functor2(T_obj&, sigc::bound_mem_functor2<T_return, T_obj, T_arg1, T_arg2>::function_type) [with T_return = void, T_obj = project::gui::Config, T_arg1 = _GtkNotebookPage*, T_arg2 = unsigned int, sigc::bound_mem_functor2<T_return, T_obj, T_arg1, T_arg2>::function_type = void (project::gui::Config::*)(_GtkNotebookPage*, unsigned int)]’:
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:5501:77: instantiated from ‘sigc::bound_mem_functor2<T_return, T_obj, T_arg1, T_arg2> sigc::mem_fun(T_obj&, T_return (T_obj2::*)(T_arg1, T_arg2)) [with T_arg1 = _GtkNotebookPage*, T_arg2 = unsigned int, T_return = void, T_obj = project::gui::Config, T_obj2 = project::gui::Config]’
src/gui/Config.cpp:70:94: instantiated from here
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:1908:18: error: using invalid field ‘sigc::bound_mem_functor2<T_return, T_obj, T_arg1, T_arg2>::obj_’
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h: In constructor ‘sigc::bound_mem_functor0<T_return, T_obj>::bound_mem_functor0(T_obj&, sigc::bound_mem_functor0<T_return, T_obj>::function_type) [with T_return = void, T_obj = project::gui::Config, sigc::bound_mem_functor0<T_return, T_obj>::function_type = void (project::gui::Config::*)()]’:
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:5453:61: instantiated from ‘sigc::bound_mem_functor0<T_return, T_obj> sigc::mem_fun(T_obj&, T_return (T_obj2::*)()) [with T_return = void, T_obj = project::gui::Config, T_obj2 = project::gui::Config]’
src/gui/Config.cpp:72:95: instantiated from here
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:1780:18: error: using invalid field ‘sigc::bound_mem_functor0<T_return, T_obj>::obj_’
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h: In function ‘void sigc::visit_each(const T_action&, const sigc::bound_mem_functor2<T_return, T_obj, T_arg1, T_arg2>&) [with T_action = sigc::internal::limit_derived_target<sigc::trackable*, sigc::internal::slot_do_bind>, T_return = void, T_obj = project::gui::Config, T_arg1 = _GtkNotebookPage*, T_arg2 = unsigned int]’:
/usr/include/sigc++-2.0/sigc++/adaptors/adaptor_trait.h:267:3: instantiated from ‘void sigc::visit_each(const T_action&, const sigc::adaptor_functor<T_functor>&) [with T_action = sigc::internal::limit_derived_target<sigc::trackable*, sigc::internal::slot_do_bind>, T_functor = sigc::bound_mem_functor2<void, project::gui::Config, _GtkNotebookPage*, unsigned int>]’
/usr/include/sigc++-2.0/sigc++/visit_each.h:170:3: instantiated from ‘void sigc::visit_each_type(const T_action&, const T_functor&) [with T_type = sigc::trackable*, T_action = sigc::internal::slot_do_bind, T_functor = sigc::adaptor_functor<sigc::bound_mem_functor2<void, project::gui::Config, _GtkNotebookPage*, unsigned int> >]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:39:7: instantiated from ‘sigc::internal::typed_slot_rep<T_functor>::typed_slot_rep(const T_functor&) [with T_functor = sigc::bound_mem_functor2<void, project::gui::Config, _GtkNotebookPage*, unsigned int>]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:604:65: instantiated from ‘sigc::slot2<T_return, T_arg1, T_arg2>::slot2(const T_functor&) [with T_functor = sigc::bound_mem_functor2<void, project::gui::Config, _GtkNotebookPage*, unsigned int>, T_return = void, T_arg1 = _GtkNotebookPage*, T_arg2 = unsigned int]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:1184:26: instantiated from ‘sigc::slot<T_return, T_arg1, T_arg2, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil>::slot(const T_functor&) [with T_functor = sigc::bound_mem_functor2<void, project::gui::Config, _GtkNotebookPage*, unsigned int>, T_return = void, T_arg1 = _GtkNotebookPage*, T_arg2 = unsigned int]’
src/gui/Config.cpp:70:95: instantiated from here
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:1936:3: error: ‘const class sigc::bound_mem_functor2<void, project::gui::Config, _GtkNotebookPage*, unsigned int>’ has no member named ‘obj_’
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h: In member function ‘T_return sigc::bound_mem_functor2<T_return, T_obj, T_arg1, T_arg2>::operator()(typename sigc::type_trait<T_arg3>::take, typename sigc::type_trait<T_arg4>::take) const [with T_return = void, T_obj = project::gui::Config, T_arg1 = _GtkNotebookPage*, T_arg2 = unsigned int, typename sigc::type_trait<T_arg3>::take = _GtkNotebookPage* const&, typename sigc::type_trait<T_arg4>::take = const unsigned int&]’:
/usr/include/sigc++-2.0/sigc++/adaptors/adaptor_trait.h:103:39: instantiated from ‘typename sigc::adaptor_functor<T_functor>::deduce_result_type<T_arg1, T_arg2>::type sigc::adaptor_functor<T_functor>::operator()(T_arg1, T_arg2) const [with T_arg1 = _GtkNotebookPage* const&, T_arg2 = const unsigned int&, T_functor = sigc::bound_mem_functor2<void, project::gui::Config, _GtkNotebookPage*, unsigned int>, typename sigc::adaptor_functor<T_functor>::deduce_result_type<T_arg1, T_arg2>::type = void]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:173:25: instantiated from ‘static T_return sigc::internal::slot_call2<T_functor, T_return, T_arg1, T_arg2>::call_it(sigc::internal::slot_rep*, typename sigc::type_trait<T_arg3>::take, typename sigc::type_trait<T_arg4>::take) [with T_functor = sigc::bound_mem_functor2<void, project::gui::Config, _GtkNotebookPage*, unsigned int>, T_return = void, T_arg1 = _GtkNotebookPage*, T_arg2 = unsigned int, typename sigc::type_trait<T_arg3>::take = _GtkNotebookPage* const&, typename sigc::type_trait<T_arg4>::take = const unsigned int&]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:180:45: instantiated from ‘static void* (* sigc::internal::slot_call2<T_functor, T_return, T_arg1, T_arg2>::address())(void*) [with T_functor = sigc::bound_mem_functor2<void, project::gui::Config, _GtkNotebookPage*, unsigned int>, T_return = void, T_arg1 = _GtkNotebookPage*, T_arg2 = unsigned int, void* (*)(void*) = void* (*)(void*)]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:607:7: instantiated from ‘sigc::slot2<T_return, T_arg1, T_arg2>::slot2(const T_functor&) [with T_functor = sigc::bound_mem_functor2<void, project::gui::Config, _GtkNotebookPage*, unsigned int>, T_return = void, T_arg1 = _GtkNotebookPage*, T_arg2 = unsigned int]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:1184:26: instantiated from ‘sigc::slot<T_return, T_arg1, T_arg2, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil>::slot(const T_functor&) [with T_functor = sigc::bound_mem_functor2<void, project::gui::Config, _GtkNotebookPage*, unsigned int>, T_return = void, T_arg1 = _GtkNotebookPage*, T_arg2 = unsigned int]’
src/gui/Config.cpp:70:95: instantiated from here
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:1917:61: error: using invalid field ‘sigc::bound_mem_functor2<T_return, T_obj, T_arg1, T_arg2>::obj_’
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:1917:61: error: return-statement with a value, in function returning 'void'
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h: In function ‘void sigc::visit_each(const T_action&, const sigc::bound_mem_functor0<T_return, T_obj>&) [with T_action = sigc::internal::limit_derived_target<sigc::trackable*, sigc::internal::slot_do_bind>, T_return = void, T_obj = project::gui::Config]’:
/usr/include/sigc++-2.0/sigc++/adaptors/adaptor_trait.h:267:3: instantiated from ‘void sigc::visit_each(const T_action&, const sigc::adaptor_functor<T_functor>&) [with T_action = sigc::internal::limit_derived_target<sigc::trackable*, sigc::internal::slot_do_bind>, T_functor = sigc::bound_mem_functor0<void, project::gui::Config>]’
/usr/include/sigc++-2.0/sigc++/visit_each.h:170:3: instantiated from ‘void sigc::visit_each_type(const T_action&, const T_functor&) [with T_type = sigc::trackable*, T_action = sigc::internal::slot_do_bind, T_functor = sigc::adaptor_functor<sigc::bound_mem_functor0<void, project::gui::Config> >]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:39:7: instantiated from ‘sigc::internal::typed_slot_rep<T_functor>::typed_slot_rep(const T_functor&) [with T_functor = sigc::bound_mem_functor0<void, project::gui::Config>]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:451:65: instantiated from ‘sigc::slot0<T_return>::slot0(const T_functor&) [with T_functor = sigc::bound_mem_functor0<void, project::gui::Config>, T_return = void]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:1130:26: instantiated from ‘sigc::slot<T_return, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil>::slot(const T_functor&) [with T_functor = sigc::bound_mem_functor0<void, project::gui::Config>, T_return = void]’
src/gui/Config.cpp:72:96: instantiated from here
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:1806:3: error: ‘const class sigc::bound_mem_functor0<void, project::gui::Config>’ has no member named ‘obj_’
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h: In member function ‘T_return sigc::bound_mem_functor0<T_return, T_obj>::operator()() const [with T_return = void, T_obj = project::gui::Config]’:
/usr/include/sigc++-2.0/sigc++/adaptors/adaptor_trait.h:251:21: instantiated from ‘sigc::adaptor_functor<T_functor>::result_type sigc::adaptor_functor<T_functor>::operator()() const [with T_functor = sigc::bound_mem_functor0<void, project::gui::Config>, sigc::adaptor_functor<T_functor>::result_type = void]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:103:36: instantiated from ‘static T_return sigc::internal::slot_call0<T_functor, T_return>::call_it(sigc::internal::slot_rep*) [with T_functor = sigc::bound_mem_functor0<void, project::gui::Config>, T_return = void]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:110:45: instantiated from ‘static void* (* sigc::internal::slot_call0<T_functor, T_return>::address())(void*) [with T_functor = sigc::bound_mem_functor0<void, project::gui::Config>, T_return = void, void* (*)(void*) = void* (*)(void*)]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:454:7: instantiated from ‘sigc::slot0<T_return>::slot0(const T_functor&) [with T_functor = sigc::bound_mem_functor0<void, project::gui::Config>, T_return = void]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:1130:26: instantiated from ‘sigc::slot<T_return, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil>::slot(const T_functor&) [with T_functor = sigc::bound_mem_functor0<void, project::gui::Config>, T_return = void]’
src/gui/Config.cpp:72:96: instantiated from here
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:1787:49: error: using invalid field ‘sigc::bound_mem_functor0<T_return, T_obj>::obj_’
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:1787:49: error: return-statement with a value, in function returning 'void'
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h: In function ‘void sigc::visit_each(const T_action&, const sigc::bound_mem_functor2<T_return, T_obj, T_arg1, T_arg2>&) [with T_action = sigc::internal::limit_derived_target<sigc::trackable*, sigc::internal::slot_do_unbind>, T_return = void, T_obj = project::gui::Config, T_arg1 = _GtkNotebookPage*, T_arg2 = unsigned int]’:
/usr/include/sigc++-2.0/sigc++/adaptors/adaptor_trait.h:267:3: instantiated from ‘void sigc::visit_each(const T_action&, const sigc::adaptor_functor<T_functor>&) [with T_action = sigc::internal::limit_derived_target<sigc::trackable*, sigc::internal::slot_do_unbind>, T_functor = sigc::bound_mem_functor2<void, project::gui::Config, _GtkNotebookPage*, unsigned int>]’
/usr/include/sigc++-2.0/sigc++/visit_each.h:170:3: instantiated from ‘void sigc::visit_each_type(const T_action&, const T_functor&) [with T_type = sigc::trackable*, T_action = sigc::internal::slot_do_unbind, T_functor = sigc::adaptor_functor<sigc::bound_mem_functor2<void, project::gui::Config, _GtkNotebookPage*, unsigned int> >]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:60:7: instantiated from ‘static void* sigc::internal::typed_slot_rep<T_functor>::destroy(void*) [with T_functor = sigc::bound_mem_functor2<void, project::gui::Config, _GtkNotebookPage*, unsigned int>]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:38:52: instantiated from ‘sigc::internal::typed_slot_rep<T_functor>::typed_slot_rep(const T_functor&) [with T_functor = sigc::bound_mem_functor2<void, project::gui::Config, _GtkNotebookPage*, unsigned int>]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:604:65: instantiated from ‘sigc::slot2<T_return, T_arg1, T_arg2>::slot2(const T_functor&) [with T_functor = sigc::bound_mem_functor2<void, project::gui::Config, _GtkNotebookPage*, unsigned int>, T_return = void, T_arg1 = _GtkNotebookPage*, T_arg2 = unsigned int]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:1184:26: instantiated from ‘sigc::slot<T_return, T_arg1, T_arg2, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil>::slot(const T_functor&) [with T_functor = sigc::bound_mem_functor2<void, project::gui::Config, _GtkNotebookPage*, unsigned int>, T_return = void, T_arg1 = _GtkNotebookPage*, T_arg2 = unsigned int]’
src/gui/Config.cpp:70:95: instantiated from here
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:1936:3: error: ‘const class sigc::bound_mem_functor2<void, project::gui::Config, _GtkNotebookPage*, unsigned int>’ has no member named ‘obj_’
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h: In function ‘void sigc::visit_each(const T_action&, const sigc::bound_mem_functor0<T_return, T_obj>&) [with T_action = sigc::internal::limit_derived_target<sigc::trackable*, sigc::internal::slot_do_unbind>, T_return = void, T_obj = project::gui::Config]’:
/usr/include/sigc++-2.0/sigc++/adaptors/adaptor_trait.h:267:3: instantiated from ‘void sigc::visit_each(const T_action&, const sigc::adaptor_functor<T_functor>&) [with T_action = sigc::internal::limit_derived_target<sigc::trackable*, sigc::internal::slot_do_unbind>, T_functor = sigc::bound_mem_functor0<void, project::gui::Config>]’
/usr/include/sigc++-2.0/sigc++/visit_each.h:170:3: instantiated from ‘void sigc::visit_each_type(const T_action&, const T_functor&) [with T_type = sigc::trackable*, T_action = sigc::internal::slot_do_unbind, T_functor = sigc::adaptor_functor<sigc::bound_mem_functor0<void, project::gui::Config> >]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:60:7: instantiated from ‘static void* sigc::internal::typed_slot_rep<T_functor>::destroy(void*) [with T_functor = sigc::bound_mem_functor0<void, project::gui::Config>]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:38:52: instantiated from ‘sigc::internal::typed_slot_rep<T_functor>::typed_slot_rep(const T_functor&) [with T_functor = sigc::bound_mem_functor0<void, project::gui::Config>]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:451:65: instantiated from ‘sigc::slot0<T_return>::slot0(const T_functor&) [with T_functor = sigc::bound_mem_functor0<void, project::gui::Config>, T_return = void]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:1130:26: instantiated from ‘sigc::slot<T_return, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil, sigc::nil>::slot(const T_functor&) [with T_functor = sigc::bound_mem_functor0<void, project::gui::Config>, T_return = void]’
src/gui/Config.cpp:72:96: instantiated from here
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:1806:3: error: ‘const class sigc::bound_mem_functor0<void, project::gui::Config>’ has no member named ‘obj_’
make: *** [src/gui/Config.o] Error 1
我们不确定问题是否真的与库sigc ++有关,或者它是否只是命名空间问题。 当我们在一个单独的文件中编译没有命名空间的同一个文件时,它就可以了。
任何想法都表示赞赏,问候
答案 0 :(得分:2)
您的课程是私下继承自Gtk::Window
class gui::Config : Gtk::Window
VS
class gui::Config : public Gtk::Window
看起来信号正在尝试连接到这些接口,但它们无法访问。
答案 1 :(得分:0)
您需要将所有三个名称空间导入到提供定义的文件中。
using namespace project;
using namespace gui;
using namespace gtk;
void Config::connect_signals()
{
// ...
}
但我看到project, gui
名称空间是多余的。 Config
已在命名空间project
中。我不明白你的评论说gui
命名空间在其他地方被声明。这就足够了 -
namespace project
{
class Config : Gtk::Window // The class being inherited is from a different namespace
{
//...