home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!snorkelwacker.mit.edu!ai-lab!life.ai.mit.edu!tmb
- From: tmb@arolla.idiap.ch (Thomas M. Breuel)
- Newsgroups: comp.lang.c++
- Subject: backwards references in templates
- Message-ID: <TMB.92Sep7163720@arolla.idiap.ch>
- Date: 7 Sep 92 20:37:20 GMT
- Sender: news@ai.mit.edu
- Reply-To: tmb@idiap.ch
- Distribution: comp
- Organization: IDIAP (Institut Dalle Molle d'Intelligence Artificielle
- Perceptive)
- Lines: 24
-
- The following definition of Foo appears to be illegal (GNU C++ doesn't
- accept it, and the ARM doesn't seem to sanction it):
-
- template <class K,K x>
- struct Foo {
- K y;
- Foo() { y = x; }
- };
-
- This restriction on the uses of template arguments (as in "Foo") is a
- serious problem, since such dependencies occur frequently.
-
- First, I'd like to know: are such template constructs indeed
- prohibited by the language definition?
-
- Second, I'd like to know what alternative paradigms there are. The
- only one that I can think of involves nested template classes
- (inconvenient, doesn't work in any existing compiler). In some cases,
- non-type template arguments like "x" can also be made (static) data
- members, but that implies runtime space/time overhead, and the use of
- static members requires a separate source file for initialization.
- Are there any more satisfactory solutions?
-
- Thomas.
-