Re: [gtkmm] General C++ Design Question: relation of GUI toapplication



On Tue, 2002-07-02 at 09:04, Stephen G. Tashiro wrote:
> I can usually find an example of a call to slot(...) which fits what I am trying
> to do.  But I really don't understand exactly what kind of animal slot(..) is and
> how it can really be "type safe"?    The same for gtk_timeout_add(..).

Typesafe means if I define Signal<void, int, float>, I'm going to have a
place to connect functions of the signature:

void func(int, float);

I can't connect any of these:

int func2(int, float);
void func3(float, int);
Foo func4(const Bar&, const Baz&);

Which means that some code that will use 'emit(2, 3.1415926)' won't
cause a core dump because we've accidentally connected func4 to the
signal.  The compiler won't let us connect func4 by punting on the
types.

What you are doing is willfully circumventing typechecking by
effectively providing no type (void *).  Then it becomes up to you to be
careful about the types you pass through.

I believe you could also write the signal:

Signal<void, BaseClass*> sig1;

Then you can pass any pointer derived from BaseClass through the
sig1.emit(...), and at the other end you can be at least assured that
you are dealing with some form of BaseClass, whether it be actual or
derived-from.  (Someone correct me if I'm wrong here)

So it's up to you how much type-checking you allow, based on the types
you give to the Signal template args.

Regards,
Carl




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