[sigc] g++ compilation problem



Hi to all:

My name is Mauricio and I write you from Chili, I have some begining question so please be patience with me, probably is only a simple "include" compilation problem..

I work with events in C# and java so I understend (I think :-) the theory, but I have problems with some very simple libgsigc++ examples (Fedora core 5, libsigc++2.0), I find the examples in some libsigc++examples rpm paquage. The problems came when I try to connect a method from a object to a slot, the compilation message is this:

g++ signals.cc -o signals `pkg-config --cflags --libs sigc++-2.0`
/usr/include/sigc++-2.0/sigc++/functors/slot.h: In function ‘int main()’:
/usr/include/sigc++-2.0/sigc++/functors/slot.h:1089: error: ‘template<class T_return, class T_arg1, class T_arg2, class T_arg3, class T_arg4, class T_arg5, class T_arg6, class T_arg7> class sigc::slot’ is not a function, /usr/include/sigc++-2.0/sigc++/object_slot.h:527: error: conflict with ‘template<class T_return, class T_arg1, class T_arg2, class T_arg3...

So I think that is only a include problem or some compilation flag...any idea??,

In advance thanks, and here is the code....:

// Copyright 1999 Karl Nelson.
//
// Okay here is a complete primer on basic use of signals.

#include <iostream>
#include <string>
// (1) Include the signal system in headers file.
//#include <sigc++/signal_system.h> // ORIGINAL INCLUDE FROM DE EXAMPLE, DON'T WORK //WITH FEDORA // I TRY WITH SEVERAL INCLUDE SCHEMA THE UNCOMENTED ONES ARE THE BEST FOR //NOW, I DON'T KNOW IF IS CORRECT
#include <sigc++/sigc++.h>
#include <sigc++/slot.h>
//#include <sigc++/functors/slot.h>
//#include <sigc++/object.h>
#include <sigc++/object_slot.h>
//#include <sigc++/signal_base.h>
//#include <sigc++/signal.h>



//SIGCXX_SIGCXX_H
// (2) If your compiler supports name spaces, you should use namespace SigC
// It is not necessary to include the entire space. However, if you
// include all you should do so in each source file.
//#ifdef SIGC_CXX_NAMESPACES
using namespace SigC;
using namespace std;
//#endif

// Some procedures to connect to.
int foo1(int i)
{
cout<<"f("<<i<<");"<<endl;
return 1;
}

int foo2(int i)
{
cout<<"sig2::f("<<i<<");"<<endl;
return 1;
}

void foo1v(int i)
{
cout<<"fv("<<i<<");"<<endl;
}

void foo2v(int i)
{
cout<<"sig2::fv("<<i<<");"<<endl;
}

// (3) Objects which are to be connected must be derived from SigC::Object.
struct A : public Object
{
//public:
A()
{
}
int foo(int i)
{
cout<<"A::f("<<i<<");"<<endl;
return 1;
}

void foov(int i)
{
cout<<"A::fv("<<i<<");"<<endl;
}


};

int main()
{
A a;

//a.foo(5);

// (4) Signals can be declared anywhere, including as class members
// Their size is about that of 2 pointers.
// Signals contain their callback signature as template parameters.
// The number following it is the number of parameters, and the
// first argument is the return type.
//
// So to declare a signal called like int foo(int) would be
// Signal1< int, int> foo;

// Lets declare a few signals.
Signal1<int,int> sig1; // int sig1(int);
Signal1<int,int> sig2; // int sig2(int);

// The return type is allowed to be void.
Signal1<void,int> sig1v; // void sig(int);
Signal1<void,int> sig2v; // void sig2(int);

// (5) After the signals are declared you can establish
// connections between them and functions and methods.
cout << ">> Connect to signals "<< endl;

// Connect to function foo.
sig1.connect(slot(foo1));

// IF I TRY TO CONNECT A METHOD FROM A OBJECT DON'T COMPILE
// Connect to method foo of object a.
//sig1.connect(slot(a,&A::foo)); //OJO DESCOMENTADA NO COMPILA !!!

// Connect to signal 1 to signal 2. Thus all things in signal2
// are also called.
//sig1.connect(sig2.slot()); OJO DESCOMENTADA NO COMPILA !!!

// We can do the same for the void signals.
sig1v.connect(slot(foo1v));
//sig1v.connect(slot(a,&A::foov)); //OJO DESCOMENTADA NO COMPILA !!!
sig1v.connect(sig2v.slot());

sig2.connect(slot(foo2));
sig2v.connect(slot(foo2v));

// (6) After connection the signals can be "emitted".
// This calls all the callbacks stored within the signal.
// (Emits are generally called reverse of the order connected,
// however this is implementation specific.)
cout << ">> Emit signals "<< endl;

// Explicitly calling the emits.
sig1.emit(1);
//sig1v.emit(2); //OJO DESCOMENTADA NO COMPILA !!!

// Or alternatively they can be called as a function object
// with operator()
sig1(1);
//sig1v(2); //OJO DESCOMENTADA NO COMPILA !!!

return 0;
}


Mauricio.




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]