Compilation problem sigc++/gtkmm in own namespaces - c++

Having our own namespaces in a project, we would like to include a GUI using gtkmm.
// 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();
};
}
It all works until i try to implement this method:
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));
}
We are then compiling Config.cpp using pkg-config --cflags gtkmm-2.4 and pkg-config --libs gtkmm-2.4.
The compiler finally throws the following message:
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
We're not sure if the problem really is related to the library sigc++ or if it's just a namespace problem.
When we compiled the same file without the namespaces in a separate file, it worked.
Any idea is appreciated, Regards

Your class is privately inheriting from Gtk::Window
class gui::Config : Gtk::Window
vs
class gui::Config : public Gtk::Window
It looks like signals are trying to connect to these interfaces, but they are inaccessible.

You need to import all the three namespaces to the file where definitions are being provided.
using namespace project;
using namespace gui;
using namespace gtk;
void Config::connect_signals()
{
// ...
}
But I see project, gui namespaces are redundant. Already Config is in namespace project. I don't understand your comment saying gui namespace is declared else where. This would suffice -
namespace project
{
class Config : Gtk::Window // The class being inherited is from a different namespace
{
//...

Related

Understanding the compiler errors with std::bind

How do I get this to compile:
#include <functional>
#include <iostream>
#include <memory>
#include <string>
inline void print(std::string string1, std::string* string2)
{
std::cout << string1 << " " << string2 << std::endl;
delete string2;
}
class class1
{
public:
std::string foo{"Hello"};
std::shared_ptr<std::string> foo2;
class1();
};
class1::class1()
{
auto boundFunc = std::bind(print, foo, std::placeholders::_2);
foo2 = std::shared_ptr<std::string>(new std::string("world"), boundFunc);
}
int main()
{
class1 test;
}
GCC gives a long and cryptic bunch of error messages:
g++ -std=c++17 -o bind bind.cpp
In file included from /usr/include/c++/7.3.1/bits/shared_ptr.h:52:0,
from /usr/include/c++/7.3.1/memory:81,
from bind.cpp:21:
/usr/include/c++/7.3.1/bits/shared_ptr_base.h: In instantiation of ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(_Yp*, _Deleter) [with _Yp = std::__cxx11::basic_string<char>; _Deleter = std::_Bind<void (*(std::__cxx11::basic_string<char>, std::_Placeholder<2>))(std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char>*)>; <template-parameter-2-3> = void; _Tp = std::__cxx11::basic_string<char>; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2]’:
/usr/include/c++/7.3.1/bits/shared_ptr.h:147:48: required from ‘std::shared_ptr<_Tp>::shared_ptr(_Yp*, _Deleter) [with _Yp = std::__cxx11::basic_string<char>; _Deleter = std::_Bind<void (*(std::__cxx11::basic_string<char>, std::_Placeholder<2>))(std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char>*)>; <template-parameter-2-3> = void; _Tp = std::__cxx11::basic_string<char>]’
bind.cpp:41:76: required from here
/usr/include/c++/7.3.1/bits/shared_ptr_base.h:1090:4: error: static assertion failed: deleter expression d(p) is well-formed
static_assert(__is_invocable<_Deleter&, _Yp*&>::value,
^~~~~~~~~~~~~
/usr/include/c++/7.3.1/bits/shared_ptr_base.h: In instantiation of ‘std::__shared_count<_Lp>::__shared_count(_Ptr, _Deleter, _Alloc) [with _Ptr = std::__cxx11::basic_string<char>*; _Deleter = std::_Bind<void (*(std::__cxx11::basic_string<char>, std::_Placeholder<2>))(std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char>*)>; _Alloc = std::allocator<void>; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2]’:
/usr/include/c++/7.3.1/bits/shared_ptr_base.h:605:57: required from ‘std::__shared_count<_Lp>::__shared_count(_Ptr, _Deleter) [with _Ptr = std::__cxx11::basic_string<char>*; _Deleter = std::_Bind<void (*(std::__cxx11::basic_string<char>, std::_Placeholder<2>))(std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char>*)>; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2]’
/usr/include/c++/7.3.1/bits/shared_ptr_base.h:1088:48: required from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(_Yp*, _Deleter) [with _Yp = std::__cxx11::basic_string<char>; _Deleter = std::_Bind<void (*(std::__cxx11::basic_string<char>, std::_Placeholder<2>))(std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char>*)>; <template-parameter-2-3> = void; _Tp = std::__cxx11::basic_string<char>; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2]’
/usr/include/c++/7.3.1/bits/shared_ptr.h:147:48: required from ‘std::shared_ptr<_Tp>::shared_ptr(_Yp*, _Deleter) [with _Yp = std::__cxx11::basic_string<char>; _Deleter = std::_Bind<void (*(std::__cxx11::basic_string<char>, std::_Placeholder<2>))(std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char>*)>; <template-parameter-2-3> = void; _Tp = std::__cxx11::basic_string<char>]’
bind.cpp:41:76: required from here
/usr/include/c++/7.3.1/bits/shared_ptr_base.h:623:11: error: no match for call to ‘(std::_Bind<void (*(std::__cxx11::basic_string<char>, std::_Placeholder<2>))(std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char>*)>) (std::__cxx11::basic_string<char>*&)’
__d(__p); // Call _Deleter on __p.
~~~^~~~~
In file included from bind.cpp:19:0:
/usr/include/c++/7.3.1/functional:547:2: note: candidate: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) [with _Args = {_Args ...}; _Result = _Result; _Functor = void (*)(std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char>*); _Bound_args = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::_Placeholder<2>}]
operator()(_Args&&... __args)
^~~~~~~~
/usr/include/c++/7.3.1/functional:547:2: note: template argument deduction/substitution failed:
/usr/include/c++/7.3.1/functional:558:2: note: candidate: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) const [with _Args = {_Args ...}; _Result = _Result; _Functor = void (*)(std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char>*); _Bound_args = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::_Placeholder<2>}]
operator()(_Args&&... __args) const
^~~~~~~~
/usr/include/c++/7.3.1/functional:558:2: note: template argument deduction/substitution failed:
/usr/include/c++/7.3.1/functional:576:2: note: candidate: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) volatile [with _Args = {_Args ...}; _Result = _Result; _Functor = void (*)(std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char>*); _Bound_args = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::_Placeholder<2>}]
operator()(_Args&&... __args) volatile
^~~~~~~~
/usr/include/c++/7.3.1/functional:576:2: note: template argument deduction/substitution failed:
/usr/include/c++/7.3.1/functional:588:2: note: candidate: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) const volatile [with _Args = {_Args ...}; _Result = _Result; _Functor = void (*)(std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char>*); _Bound_args = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::_Placeholder<2>}]
operator()(_Args&&... __args) const volatile
^~~~~~~~
/usr/include/c++/7.3.1/functional:588:2: note: template argument deduction/substitution failed:
In file included from /usr/include/c++/7.3.1/bits/shared_ptr.h:52:0,
from /usr/include/c++/7.3.1/memory:81,
from bind.cpp:21:
/usr/include/c++/7.3.1/bits/shared_ptr_base.h: In instantiation of ‘void std::_Sp_counted_deleter<_Ptr, _Deleter, _Alloc, _Lp>::_M_dispose() [with _Ptr = std::__cxx11::basic_string<char>*; _Deleter = std::_Bind<void (*(std::__cxx11::basic_string<char>, std::_Placeholder<2>))(std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char>*)>; _Alloc = std::allocator<void>; __gnu_cxx::_Lock_policy _Lp = (__gnu_cxx::_Lock_policy)2]’:
bind.cpp:47:1: required from here
/usr/include/c++/7.3.1/bits/shared_ptr_base.h:470:25: error: no match for call to ‘(std::_Bind<void (*(std::__cxx11::basic_string<char>, std::_Placeholder<2>))(std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char>*)>) (std::__cxx11::basic_string<char>*&)’
{ _M_impl._M_del()(_M_impl._M_ptr); }
~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~
In file included from bind.cpp:19:0:
/usr/include/c++/7.3.1/functional:547:2: note: candidate: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) [with _Args = {_Args ...}; _Result = _Result; _Functor = void (*)(std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char>*); _Bound_args = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::_Placeholder<2>}]
operator()(_Args&&... __args)
^~~~~~~~
/usr/include/c++/7.3.1/functional:547:2: note: template argument deduction/substitution failed:
/usr/include/c++/7.3.1/functional:558:2: note: candidate: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) const [with _Args = {_Args ...}; _Result = _Result; _Functor = void (*)(std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char>*); _Bound_args = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::_Placeholder<2>}]
operator()(_Args&&... __args) const
^~~~~~~~
/usr/include/c++/7.3.1/functional:558:2: note: template argument deduction/substitution failed:
/usr/include/c++/7.3.1/functional:576:2: note: candidate: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) volatile [with _Args = {_Args ...}; _Result = _Result; _Functor = void (*)(std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char>*); _Bound_args = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::_Placeholder<2>}]
operator()(_Args&&... __args) volatile
^~~~~~~~
/usr/include/c++/7.3.1/functional:576:2: note: template argument deduction/substitution failed:
/usr/include/c++/7.3.1/functional:588:2: note: candidate: template<class ... _Args, class _Result> _Result std::_Bind<_Functor(_Bound_args ...)>::operator()(_Args&& ...) const volatile [with _Args = {_Args ...}; _Result = _Result; _Functor = void (*)(std::__cxx11::basic_string<char>, std::__cxx11::basic_string<char>*); _Bound_args = {std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >, std::_Placeholder<2>}]
operator()(_Args&&... __args) const volatile
^~~~~~~~
/usr/include/c++/7.3.1/functional:588:2: note: template argument deduction/substitution failed:
I'm not sure what to make of this output, and I haven't found any good documentation of std::bind which provides examples for all the various ways in which it might be used, only the most basic cases.
stackoverflow wants more details, but I don't even know what else to provide. It should be obvious from the code what the problem is. If I knew what to say I would be able to search for it already, but I'm not sure how to describe this problem.
Simple fix: Replace
auto boundFunc = std::bind(print, foo, std::placeholders::_2);
with
auto boundFunc = std::bind(print, foo, std::placeholders::_1);
Why?
In std::bind, the placeholders indicate the index of the argument to the result function. std::placeholders::_1 means "use the first argument passed to me in this position".
When you pass std::placeholders::_2, your boundFunc will take the wrong number of arguments (2 instead of 1) and no longer be a valid deleter for an std::shared_ptr.
The error is subtle but there. You probably used std::placeholders::_2 because you are using the second argument, right? Well, that's not how you use them.
The number _N designates that the argument number N (when you call the result) is bound to _N. In other words, you need to enumerate them from 1 onwards in your case:
auto boundFunc = std::bind(print, foo, std::placeholders::_1);
// ^

How to create std::thread with function pointer with a reference?

class taskq {
public:
int trigger(taskq &tq);
mutex mtx;
};
void func_wrapper(taskq &tq) {
cout<<endl;
}
int taskq::trigger(taskq &tq) {
thread thread(func_wrapper, tq);
return 0;
}
I tried to compile the above simple code but I am keep getting errors because of line thread thread(func_wrapper, tq);.
What's wrong with this code?
How could I fix it?
The error message is as below:
In file included from /usr/include/c++/4.9/thread:39:0,
from taskq.C:2:
/usr/include/c++/4.9/functional: In instantiation of ‘struct std::_Bind_simple<void (*(taskq))(taskq&)>’:
/usr/include/c++/4.9/thread:140:47: required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (&)(taskq&); _Args = {taskq&}]’
taskq.C:20:33: required from here
/usr/include/c++/4.9/functional:1665:61: error: no type named ‘type’ in ‘class std::result_of<void (*(taskq))(taskq&)>’
typedef typename result_of<_Callable(_Args...)>::type result_type;
^
/usr/include/c++/4.9/functional:1695:9: error: no type named ‘type’ in ‘class std::result_of<void (*(taskq))(taskq&)>’
_M_invoke(_Index_tuple<_Indices...>)
^
In file included from /usr/include/c++/4.9/functional:55:0,
from /usr/include/c++/4.9/thread:39,
from taskq.C:2:
/usr/include/c++/4.9/tuple: In instantiation of ‘constexpr std::_Head_base<_Idx, _Head, false>::_Head_base(_UHead&&) [with _UHead = taskq; <template-parameter-2-2> = void; long unsigned int _Idx = 1ul; _Head = taskq]’:
/usr/include/c++/4.9/tuple:271:42: required from ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(std::_Tuple_impl<_Idx, _Head, _Tail ...>&&) [with long unsigned int _Idx = 1ul; _Head = taskq; _Tail = {}]’
/usr/include/c++/4.9/type_traits:900:43: required by substitution of ‘template<class _Tp, class _Arg, class> static std::true_type std::__do_is_direct_constructible_impl::__test(int) [with _Tp = std::_Tuple_impl<1ul, taskq>; _Arg = std::_Tuple_impl<1ul, taskq>&&; <template-parameter-1-3> = <missing>]’
/usr/include/c++/4.9/type_traits:912:43: required from ‘struct std::__is_direct_constructible_impl<std::_Tuple_impl<1ul, taskq>, std::_Tuple_impl<1ul, taskq>&&>’
/usr/include/c++/4.9/type_traits:134:12: required from ‘struct std::__and_<std::is_destructible<std::_Tuple_impl<1ul, taskq> >, std::__is_direct_constructible_impl<std::_Tuple_impl<1ul, taskq>, std::_Tuple_impl<1ul, taskq>&&> >’
/usr/include/c++/4.9/type_traits:916:12: required from ‘struct std::__is_direct_constructible_new_safe<std::_Tuple_impl<1ul, taskq>, std::_Tuple_impl<1ul, taskq>&&>’
/usr/include/c++/4.9/type_traits:994:12: [ skipping 7 instantiation contexts, use -ftemplate-backtrace-limit=0 to disable ]
/usr/include/c++/4.9/type_traits:1175:12: required from ‘struct std::is_nothrow_move_constructible<std::_Tuple_impl<1ul, taskq> >’
/usr/include/c++/4.9/type_traits:134:12: required from ‘struct std::__and_<std::is_nothrow_move_constructible<void (*)(taskq&)>, std::is_nothrow_move_constructible<std::_Tuple_impl<1ul, taskq> > >’
/usr/include/c++/4.9/tuple:267:7: required from ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(std::_Tuple_impl<_Idx, _Head, _Tail ...>&&) [with long unsigned int _Idx = 0ul; _Head = void (*)(taskq&); _Tail = {taskq}]’
/usr/include/c++/4.9/functional:1727:41: required from ‘typename std::_Bind_simple_helper<_Func, _BoundArgs>::__type std::__bind_simple(_Callable&&, _Args&& ...) [with _Callable = void (&)(taskq&); _Args = {taskq&}; typename std::_Bind_simple_helper<_Func, _BoundArgs>::__type = std::_Bind_simple<void (*(taskq))(taskq&)>]’
/usr/include/c++/4.9/thread:140:47: required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (&)(taskq&); _Args = {taskq&}]’
taskq.C:20:33: required from here
/usr/include/c++/4.9/tuple:140:42: error: use of deleted function ‘taskq::taskq(taskq&&)’
: _M_head_impl(std::forward<_UHead>(__h)) { }
^
taskq.C:9:7: note: ‘taskq::taskq(taskq&&)’ is implicitly deleted because the default definition would be ill-formed:
class taskq {
^
taskq.C:9:7: error: use of deleted function ‘std::mutex::mutex(const std::mutex&)’
In file included from taskq.C:3:0:
/usr/include/c++/4.9/mutex:129:5: note: declared here
mutex(const mutex&) = delete;
^
In file included from /usr/include/c++/4.9/functional:55:0,
from /usr/include/c++/4.9/thread:39,
from taskq.C:2:
/usr/include/c++/4.9/tuple: In instantiation of ‘constexpr std::_Head_base<_Idx, _Head, false>::_Head_base(const _Head&) [with long unsigned int _Idx = 1ul; _Head = taskq]’:
/usr/include/c++/4.9/tuple:255:44: recursively required from ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const _Head&, const _Tail& ...) [with long unsigned int _Idx = 1ul; _Head = taskq; _Tail = {}]’
/usr/include/c++/4.9/tuple:255:44: required from ‘constexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const _Head&, const _Tail& ...) [with long unsigned int _Idx = 0ul; _Head = void (*)(taskq&); _Tail = {taskq}]’
/usr/include/c++/4.9/tuple:531:30: required from ‘constexpr std::tuple<_T1, _T2>::tuple(const _T1&, const _T2&) [with _T1 = void (*)(taskq&); _T2 = taskq]’
/usr/include/c++/4.9/functional:1678:74: required from ‘std::_Bind_simple<_Callable(_Args ...)>::_Bind_simple(_Callable&&, _Args2&& ...) [with _Args2 = {taskq&}; <template-parameter-2-2> = void; _Callable = void (*)(taskq&); _Args = {taskq}]’
/usr/include/c++/4.9/functional:1727:41: required from ‘typename std::_Bind_simple_helper<_Func, _BoundArgs>::__type std::__bind_simple(_Callable&&, _Args&& ...) [with _Callable = void (&)(taskq&); _Args = {taskq&}; typename std::_Bind_simple_helper<_Func, _BoundArgs>::__type = std::_Bind_simple<void (*(taskq))(taskq&)>]’
/usr/include/c++/4.9/thread:140:47: required from ‘std::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (&)(taskq&); _Args = {taskq&}]’
taskq.C:20:33: required from here
/usr/include/c++/4.9/tuple:134:25: error: use of deleted function ‘taskq::taskq(const taskq&)’
: _M_head_impl(__h) { }
^
taskq.C:9:7: note: ‘taskq::taskq(const taskq&)’ is implicitly deleted because the default definition would be ill-formed:
class taskq {
^
taskq.C:9:7: error: use of deleted function ‘std::mutex::mutex(const std::mutex&)’
In file included from taskq.C:3:0:
/usr/include/c++/4.9/mutex:129:5: note: declared here
mutex(const mutex&) = delete;
^
make: *** [taskq.o] Error 1
thread thread(func_wrapper, std::ref(tq));
Note that you need to make sure the reference is still valid while you are executing func_wrapper (since I'm guessing such function uses tq).
std::thread thread([&tq]() {
func_wrapper(tq);
});

gtkmm compiler error when connecting signal

I'm working on an application with a GUI and I'm having trouble when trying to emit a signal (sig_showList, from View) at the connect for another signal (signal_changed, from Gtk::ComboBox), I'd really appreciate your help. The code looks something like this:
"view.h"
class View{
private:
Gtk::ComboBox* combo;
sigc::signal<void,int> sig_showList;
public:
View();
...
};
"view.c"
#include "view.h"
View::View(Glib::RefPtr<Gtk::Builder>& builder){
builder -> get_widget("combo",combo);
combo->signal_changed().connect(sigc::mem_fun(&sig_showList,&sigc::signal<void,int>::emit));
...
}
I compile it with g++ -std=c++98 *.cpp -o out $(pkg-config gtkmm-3.0 --cflags --libs). The error I'm getting is:
In file included from /usr/include/sigc++-2.0/sigc++/functors/slot.h:7:0,
from /usr/include/sigc++-2.0/sigc++/signal_base.h:29,
from /usr/include/sigc++-2.0/sigc++/signal.h:8,
from /usr/include/sigc++-2.0/sigc++/sigc++.h:80,
from /usr/include/glibmm-2.4/glibmm/thread.h:58,
from /usr/include/glibmm-2.4/glibmm.h:87,
from /usr/include/gtkmm-3.0/gtkmm.h:87,
from vista.cpp:2:
/usr/include/sigc++-2.0/sigc++/adaptors/adaptor_trait.h: In instantiation of ‘sigc::adaptor_functor<T_functor>::result_type sigc::adaptor_functor<T_functor>::operator()() const [with T_functor = sigc::bound_const_mem_functor1<void, sigc::signal<void, int>, const int&>; sigc::adaptor_functor<T_functor>::result_type = void]’:
/usr/include/sigc++-2.0/sigc++/functors/slot.h:103:36: required from ‘static T_return sigc::internal::slot_call0<T_functor, T_return>::call_it(sigc::internal::slot_rep*) [with T_functor = sigc::bound_const_mem_functor1<void, sigc::signal<void, int>, const int&>; T_return = void]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:110:37: required from ‘static void* (* sigc::internal::slot_call0<T_functor, T_return>::address())(void*) [with T_functor = sigc::bound_const_mem_functor1<void, sigc::signal<void, int>, const int&>; T_return = void; sigc::internal::hook = void* (*)(void*)]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:454:83: required from ‘sigc::slot0<T_return>::slot0(const T_functor&) [with T_functor = sigc::bound_const_mem_functor1<void, sigc::signal<void, int>, const int&>; T_return = void]’
/usr/include/sigc++-2.0/sigc++/functors/slot.h:1130:26: required 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_const_mem_functor1<void, sigc::signal<void, int>, const int&>; T_return = void]’
vista.cpp:80:105: required from here
/usr/include/sigc++-2.0/sigc++/adaptors/adaptor_trait.h:251:21: error: no match for call to ‘(sigc::bound_const_mem_functor1<void, sigc::signal<void, int>, const int&>) ()’
{ return functor_(); }
^
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:29,
from /usr/include/sigc++-2.0/sigc++/signal.h:8,
from /usr/include/sigc++-2.0/sigc++/sigc++.h:80,
from /usr/include/glibmm-2.4/glibmm/thread.h:58,
from /usr/include/glibmm-2.4/glibmm.h:87,
from /usr/include/gtkmm-3.0/gtkmm.h:87,
from vista.cpp:2:
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:2373:7: note: candidate is:
class bound_const_mem_functor1
^
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:2402:12: note: T_return sigc::bound_const_mem_functor1<T_return, T_obj, T_arg1>::operator()(typename sigc::type_trait<T_arg3>::take) const [with T_return = void; T_obj = sigc::signal<void, int>; T_arg1 = const int&; typename sigc::type_trait<T_arg3>::take = const int&]
T_return operator()(typename type_trait<T_arg1>::take _A_a1) const
^
/usr/include/sigc++-2.0/sigc++/functors/mem_fun.h:2402:12: note: candidate expects 1 argument, 0 provided
In file included from /usr/include/sigc++-2.0/sigc++/functors/slot.h:7:0,
from /usr/include/sigc++-2.0/sigc++/signal_base.h:29,
from /usr/include/sigc++-2.0/sigc++/signal.h:8,
from /usr/include/sigc++-2.0/sigc++/sigc++.h:80,
from /usr/include/glibmm-2.4/glibmm/thread.h:58,
from /usr/include/glibmm-2.4/glibmm.h:87,
from /usr/include/gtkmm-3.0/gtkmm.h:87,
from vista.cpp:2:
/usr/include/sigc++-2.0/sigc++/adaptors/adaptor_trait.h:251:21: error: return-statement with a value, in function returning 'void' [-fpermissive]
{ return functor_(); }
^
make: *** [all] Error 1
[The actual class is called "Vista"]
So well, I have no idea what that means! Moreover this had already happened and somehow I managed to solve it but after some reformat and redesign it showed up again and I don't know what to do. It definitely has to do with the combo->signal_clicked().connect(...) line, because when I remove it compiles fine.
I found out what was wrong: the signal I'm trying to emit is of type sigc::signal so it should take one int as an argument when emitted, but I wasn't passing any arguments
Please try to used below namespace:
namespace sigc { SIGC_FUNCTORS_HAVE_RESULT_TYPE }

Passing an object by reference in C++

Before people start telling me to do a google search for my problem, let me say I've been trying for quite a while.
I can't figure out how to pass an object by reference in C++, I keep getting a massive printout of compiler errors. I can include them if they would help. Specifically, I'm trying to pass the RSSFeed object feed by reference to the function parseFeed in a thread.
void parseFeed(RSSFeed& feed) {
//dostuff
}
RSSFeed feed();
thread(parseFeed, feed); // line 119
errors:
g++ -g -Wall -pedantic -O0 -std=c++0x -D_GLIBCXX_USE_NANOSLEEP -D_GLIBCXX_USE_SCHED_YIELD -I/usr/class/cs110/include/libxml2 -I/usr/class/cs110/local/include -c -o news-aggregator.o news-aggregator.cc
In file included from /usr/include/c++/4.6/functional:56:0,
from /usr/include/c++/4.6/bits/stl_algo.h:68,
from /usr/include/c++/4.6/algorithm:63,
from news-aggregator.cc:14:
rss-feed.h: In constructor âconstexpr std::_Head_base<_Idx, _Head, false>::_Head_base(const _Head&) [with long unsigned int _Idx = 0ul, _Head = RSSFeed]â:
/usr/include/c++/4.6/tuple:162:44: instantiated from âconstexpr std::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(const _Head&, const _Tail& ...) [with long unsigned int _Idx = 0ul, _Head = RSSFeed, _Tail = {}]â
/usr/include/c++/4.6/tuple:423:24: instantiated from âconstexpr std::tuple<_T1>::tuple(const _T1&) [with _T1 = RSSFeed]â
/usr/include/c++/4.6/functional:1362:70: instantiated from âstd::_Bind_result<_Result, _Functor(_Bound_args ...)>::_Bind_result(_Functor&&, _Args&& ...) [with _Args = {RSSFeed&}, _Result = void, _Functor = void (*)(RSSFeed&), _Bound_args = {RSSFeed}]â
/usr/include/c++/4.6/functional:1477:41: instantiated from âtypename std::_Bindres_helper<_Result, _Functor, _ArgTypes>::type std::bind(_Functor&&, _ArgTypes&& ...) [with _Result = void, _Functor = void (&)(RSSFeed&), _ArgTypes = {RSSFeed&}, typename std::_Bindres_helper<_Result, _Functor, _ArgTypes>::type = std::_Bind_result<void, void (*(RSSFeed))(RSSFeed&)>]â
/usr/include/c++/4.6/thread:135:9: instantiated from âstd::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (&)(RSSFeed&), _Args = {RSSFeed&}]â
news-aggregator.cc:119:25: instantiated from here
rss-feed.h:54:3: error: âRSSFeed::RSSFeed(const RSSFeed&)â is private
/usr/include/c++/4.6/tuple:97:25: error: within this context
/usr/include/c++/4.6/tuple:97:25: error: use of deleted function âRSSFeed::RSSFeed(const RSSFeed&)â
rss-feed.h:54:3: error: declared here
rss-feed.h: In constructor âstd::_Head_base<_Idx, _Head, false>::_Head_base(_UHead&&) [with _UHead = RSSFeed, long unsigned int _Idx = 0ul, _Head = RSSFeed]â:
/usr/include/c++/4.6/tuple:174:43: instantiated from âstd::_Tuple_impl<_Idx, _Head, _Tail ...>::_Tuple_impl(std::_Tuple_impl<_Idx, _Head, _Tail ...>&&) [with long unsigned int _Idx = 0ul, _Head = RSSFeed, _Tail = {}, std::_Tuple_impl<_Idx, _Head, _Tail ...> = std::_Tuple_impl<0ul, RSSFeed>]â
/usr/include/c++/4.6/tuple:434:51: instantiated from âstd::tuple<_T1>::tuple(std::tuple<_T1>&&) [with _T1 = RSSFeed, std::tuple<_T1> = std::tuple<RSSFeed>]â
/usr/include/c++/4.6/functional:1368:78: instantiated from âstd::_Bind_result<_Result, _Functor(_Bound_args ...)>::_Bind_result(std::_Bind_result<_Result, _Functor(_Bound_args ...)>&&) [with _Result = void, _Functor = void (*)(RSSFeed&), _Bound_args = {RSSFeed}, std::_Bind_result<_Result, _Functor(_Bound_args ...)> = std::_Bind_result<void, void (*(RSSFeed))(RSSFeed&)>]â
/usr/include/c++/4.6/functional:1477:41: instantiated from âtypename std::_Bindres_helper<_Result, _Functor, _ArgTypes>::type std::bind(_Functor&&, _ArgTypes&& ...) [with _Result = void, _Functor = void (&)(RSSFeed&), _ArgTypes = {RSSFeed&}, typename std::_Bindres_helper<_Result, _Functor, _ArgTypes>::type = std::_Bind_result<void, void (*(RSSFeed))(RSSFeed&)>]â
/usr/include/c++/4.6/thread:135:9: instantiated from âstd::thread::thread(_Callable&&, _Args&& ...) [with _Callable = void (&)(RSSFeed&), _Args = {RSSFeed&}]â
news-aggregator.cc:119:25: instantiated from here
rss-feed.h:54:3: error: âRSSFeed::RSSFeed(const RSSFeed&)â is private
/usr/include/c++/4.6/tuple:101:42: error: within this context
/usr/include/c++/4.6/tuple:101:42: error: use of deleted function âRSSFeed::RSSFeed(const RSSFeed&)â
rss-feed.h:54:3: error: declared here
Resolved:
thread(parseFeed, ref( feed ) ); // line 119
This
RSSFeed feed();
is a function declaration that returns an object of type RSSFeed and has no parameters. It is not an object definition.
Write instead
RSSFeed feed;
Also it seems from the list of error messages that class RSSFeed has no the copy constructor that is it is defined as deleted.

Compilation Error when using tr1::function

The purpose is to execute CVS890Executor::do_full_frame when calling the m_callback_fn within CDevVS890.
Following is the incriminated code:
"CDevVS890.h"
typedef std::tr1::function<void (void* frame, int len)> DoFrameFn;
class CDevVS890
{
public:
CDevVS890();
void receive();
DoFrameFn m_callback_fn;
}
"CDevVS890.cpp"
void CDevVS890::receive()
{
...
m_callback_fn((void*)frame, (int)len);
}
/*----------------------------------------------------------------------*/
"CVS890Executor.h"
class CVS890Executor
{
public:
CVS890Executor();
private:
void hookup_to_DevVS890();
void do_full_frame( void* frame, int len );
}
"CVS890Executor.cpp"
CVS890Executor::CVS890Executor()
{
hookup_to_DevVS890();
}
void CVS890Executor::hookup_to_DevVS890()
{
m_pDevVS890 = new CDevVS890();
m_pDevVS890->m_callback_fn =
std::tr1::bind(&CVS890Executor::do_full_frame, this, _1);
}
void CVS890Executor::do_full_frame(void* frame, int len)
{
...
}
The errors are multiple and very difficult to read:
In file included from /usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/tr1/functional:56,
from ../../src/Common/CDevVS890.h:17,
from CVS890Executor.h:13,
from CVS890Executor.cpp:8:
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/tr1_impl/functional: In member function âtypename std::tr1::result_of<_Functor(typename std::tr1::result_of 0)>(_Bound_args, std::tr1::tuple<_UElements ...>)>::type ...)>::type std::tr1::_Bind<_Functor(_Bound_args ...)>::__call(const std::tr1::tuple<_UElements ...>&, std::tr1::_Index_tuple<_Indexes ...>) [with _Args = void*&, int&, int ..._Indexes = 0, 1, _Functor = std::tr1::_Mem_fn, _Bound_args = CVS890Executor*, std::tr1::_Placeholder<1>]â:
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/tr1_impl/functional:1191: instantiated from âtypename std::tr1::result_of<_Functor(typename std::tr1::result_of 0)>(_Bound_args, std::tr1::tuple<_UElements ...>)>::type ...)>::type std::tr1::_Bind<_Functor(_Bound_args ...)>::operator()(_Args& ...) [with _Args = void*, int, _Functor = std::tr1::_Mem_fn, _Bound_args = CVS890Executor*, std::tr1::_Placeholder<1>]â
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/tr1_impl/functional:1668: instantiated from âstatic void std::tr1::_Function_handler::_M_invoke(const std::tr1::_Any_data&, _ArgTypes ...) [with _Functor = std::tr1::_Bind(CVS890Executor*, std::tr1::_Placeholder<1>)>, _ArgTypes = void*, int]â
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/tr1_impl/functional:2005: instantiated from âstd::tr1::function<_Res(_ArgTypes ...)>::function(_Functor, typename __gnu_cxx::__enable_if<(! std::tr1::is_integral::value), std::tr1::function<_Res(_ArgTypes ...)>::Useless>::_type) [with _Functor = std::tr1::_Bind(CVS890Executor*, std::tr1::_Placeholder<1>)>, _Res = void, _ArgTypes = void*, int]â
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/tr1_impl/functional:1885: instantiated from âtypename __gnu_cxx::__enable_if<(! std::tr1::is_integral::value), std::tr1::function<_Res(ArgTypes ...)>&>::_type std::tr1::function<_Res(_ArgTypes ...)>::operator=(_Functor) [with _Functor = std::tr1::_Bind(CVS890Executor*, std::tr1::_Placeholder<1>)>, _Res = void, _ArgTypes = void*, int]â
CVS890Executor.cpp:115: instantiated from here
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/tr1_impl/functional:1137: error: no match for call to â(std::tr1::_Mem_fn) (CVS890Executor*&, void*&)â
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/tr1_impl/functional:546: note: candidates are: _Res std::tr1::_Mem_fn<_Res (_Class::*)(_ArgTypes ...)>::operator()(_Class&, _ArgTypes ...) const [with _Res = void, _Class = CVS890Executor, _ArgTypes = void*, int]
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/tr1_impl/functional:551: note: _Res std::tr1::_Mem_fn<_Res (_Class::*)(_ArgTypes ...)>::operator()(_Class*, _ArgTypes ...) const [with _Res = void, _Class = CVS890Executor, _ArgTypes = void*, int]
/usr/lib/gcc/x86_64-redhat-linux/4.4.6/../../../../include/c++/4.4.6/tr1_impl/functional:1137: error: return-statement with a value, in function returning 'void'
make: * [CVS890Executor.o] Error 1
Any idea what's wrong with this?
Cheers
You forgot about the second argument. Your call of bind function should be like this:
std::tr1::bind(&CVS890Executor::do_full_frame, this, _1, _2);
// ^^
In CVS890Executor::hookup_to_DevVS890(), you are not binding any arguments to the member function do_full_frame.
You are also trying to assign the return value of the function to m_callback_fn but do_full_frame() is declared to return void (no return value).