home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!spool.mu.edu!darwin.sura.net!uvaarpa!cv3.cv.nrao.edu!cv3!dschieb
- From: dschieb@muse.cv.nrao.edu (Darrell Schiebel)
- Subject: type conflict introduced by friend ...
- Message-ID: <DSCHIEB.92Dec29170442@muse.cv.nrao.edu>
- Sender: news@nrao.edu
- Organization: National Radio Astronomy Observatory
- Distribution: comp
- Date: Tue, 29 Dec 1992 22:04:42 GMT
- Lines: 41
-
-
- Since my last problem was handled so expediently, I have one other problem.
- It seems that the "friend" declaration in the templated class "typeinfo_"
- below is causing the compiler to think that there are two "different"
- "typeId" functions:
-
- class typeinfo {
- public:
- virtual const char *name() const = 0;
- };
-
- template<class t> class typeinfo_ : public typeinfo {
- friend const typeinfo *typeId(t *);
- protected:
- char *typename;
- typeinfo_(char *name) : typename(name) {}
- public:
- const char *name() const {return typename;}
- };
-
- template<class t> class templateClass {};
- template <class t> const typeinfo *typeId(templateClass<t> *) {
- static typeinfo_<templateClass<t> > xx("templateClass");
- return(&xx);
- };
-
- main() {
- templateClass<int> *fred;
- cout << (*typeId(fred)).name() << endl;
- }
-
- So when the call to "typeId" is attempted in main, I get the error:
-
- "test5.C", line 27: error: use of template function typeId() matches multiple instances
-
- Any suggestions, on how to work around this. The constructor is "protected"
- to force all access to the "typeinfo" structures to happen through the
- "typeId" functions.
-
- Thanks,
- Darrell Schiebel
-