home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / lang / cplus / 18516 < prev    next >
Encoding:
Text File  |  1992-12-29  |  1.6 KB  |  53 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!spool.mu.edu!darwin.sura.net!uvaarpa!cv3.cv.nrao.edu!cv3!dschieb
  3. From: dschieb@muse.cv.nrao.edu (Darrell Schiebel)
  4. Subject: type conflict introduced by friend ...
  5. Message-ID: <DSCHIEB.92Dec29170442@muse.cv.nrao.edu>
  6. Sender: news@nrao.edu
  7. Organization: National Radio Astronomy Observatory
  8. Distribution: comp
  9. Date: Tue, 29 Dec 1992 22:04:42 GMT
  10. Lines: 41
  11.  
  12.  
  13. Since my last problem was handled so expediently, I have one other problem.
  14. It seems that the "friend" declaration in the templated class "typeinfo_" 
  15. below is causing the compiler to think that there are two "different"
  16. "typeId" functions:
  17.  
  18.     class typeinfo {
  19.     public:
  20.       virtual const char *name() const = 0;
  21.     };
  22.  
  23.     template<class t> class typeinfo_ : public typeinfo {
  24.     friend const typeinfo *typeId(t *);
  25.     protected:
  26.       char *typename;
  27.       typeinfo_(char *name) : typename(name) {}
  28.     public:
  29.       const char *name() const {return typename;}
  30.     };
  31.  
  32.     template<class t> class templateClass {};
  33.     template <class t> const typeinfo *typeId(templateClass<t> *) {
  34.       static typeinfo_<templateClass<t> > xx("templateClass");
  35.       return(&xx);
  36.     };
  37.  
  38.     main() {
  39.       templateClass<int> *fred;
  40.       cout << (*typeId(fred)).name() << endl;
  41.     }
  42.  
  43. So when the call to "typeId" is attempted in main, I get the error:
  44.  
  45. "test5.C", line 27: error: use of template function typeId() matches multiple instances
  46.  
  47. Any suggestions, on how to work around this. The constructor is "protected"
  48. to force all access to the "typeinfo" structures to happen through the
  49. "typeId" functions.
  50.  
  51.                         Thanks,
  52.                         Darrell Schiebel
  53.