home *** CD-ROM | disk | FTP | other *** search
- Xref: sparky comp.lang.c++:16634 comp.std.c++:1604
- Newsgroups: comp.lang.c++,comp.std.c++
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!cs.utexas.edu!torn!watserv2.uwaterloo.ca!watmath!xjzhu
- From: xjzhu@math.uwaterloo.ca (Xiaojun Zhu)
- Subject: "Invalid" argument(s) in template class declaration, how to realize?
- Message-ID: <BxznCM.K9o@math.uwaterloo.ca>
- Keywords: template, argument
- Organization: University of Waterloo
- Date: Fri, 20 Nov 1992 00:14:46 GMT
- Lines: 45
-
- Q: When designing a template class, how to make sure that its argument
- can only be certain classes or certain predefined types?
-
- Another words, can we build a template class such that it only accepts
- certain types as its arguments, while for others it will generate an
- error message such as:
-
- This type is not supported by this template.
-
- if you attempt to use them as the argument.
-
- To give you an example( hopefully you will think it's reasonable! )
-
- template<class T>
- class Expect_Numerical_In_Nature
- {
- T Nian;
- public:
- // ...
- };
-
- and suppose that we also have:
-
- class Not_Numerical_In_Nature;
-
- then we will expect the following declaration:
-
- Expect_Numberical_In_Nature<Not_Numerical_In_Nature> Not_Valid;
-
- generate an error message.
-
- How do we provide such a mechanism?
-
- P.S. While I am writing this down, I feel this is probably a hard question,
- because, I think, the template of C++ doesn't provide such property?
- (Well, just guess, don't get offended if it actually does.) How hard
- will be a work around?
-
- --------------------------------------------------------------
- A template version of my signature class is under repair.
- Symptom: It dies without a warning if I use certain class
- as an argument.
-
- xjzhu@math.uwaterloo.ca
- --------------------------------------------------------------
-