home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!mcsun!ieunet!tcdcs!unix1.tcd.ie!ghawkins
- From: ghawkins@unix1.tcd.ie (George C. Hawkins)
- Subject: How do I write a typedef to go with my template class?
- Message-ID: <ghawkins.714856261@unix1.tcd.ie>
- Summary: See subject line.
- Keywords: template generic define
- Sender: usenet@cs.tcd.ie (NN required at ashe.cs.tcd.ie)
- Nntp-Posting-Host: unix1.tcd.ie
- Organization: Trinity College, Dublin
- Date: Wed, 26 Aug 1992 19:11:01 GMT
- Lines: 56
-
-
- I can use templates for classes but how do I write a typedef to go
- with a template class. At the moment I have a horrible solution
- using a massive #define. I have a '.h' file, such that if I have
- a class X and use the line:
-
- Callbackdeclare(X);
-
- I get a new class (called Callback<X> if I was using templates).
- *And* I also get a typedef to go with it. I think to reimplement
- the class to be a template class is no problem, but how do I get
- the very handy typedef to go with it. As far as I can see templates
- only have "scope" over the class or whatever that follows them. I.e.
- I can't do:
-
- template <class X>
- class Callback {
- ...
- }
- typedef void (X::func_ptr)(int);
-
- And even if I could I'd get name clashes for all my typedefs for
- Callback class being used with different X types.
-
- So what's the solution? At the moment I have this code to
- do things:
-
- #define Callbackdeclare(CLASS) \
- class CLASS; \
- \
- typedef void (CLASS::*name2(CLASS,PMF_CB))( int ); \
- \
- class name2(CLASS,Callback) { \
- \
- private: \
- \
- CLASS* _obj; \
- name2(CLASS,PMF_CB) _pmf; \
- ...
-
- Fairly ghastly stuff I guess, but it works and solves a really
- tricky problem. (If you haven't come across name2(x,y) before it's
- just a concatenation macro, so after cpp has gone through say
- 'name2(call,back)' it will be replaced by 'callback'.)
-
- So please, please help me develop a clean solution with templates.
- Thanks for your time, yours,
-
-
- George.
-
- --
- george lives at:
- ___________________________________________________________________________
- | ghawkins@unix1.tcd.ie (mostly) | ghawkins@vax1.tcd.ie (sometimes) |
- ---------------------------------------------------------------------------
-