home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / cplus / 11771 < prev    next >
Encoding:
Text File  |  1992-07-29  |  2.6 KB  |  65 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!cs.utexas.edu!qt.cs.utexas.edu!yale.edu!yale!mintaka.lcs.mit.edu!bloom-picayune.mit.edu!athena.mit.edu!fabbott
  3. From: fabbott@athena.mit.edu (Freeland K Abbott III)
  4. Subject: Help: TC++ template-of-const-ptr problem
  5. Message-ID: <FABBOTT.92Jul29224620@e40-008-6.mit.edu>
  6. Sender: news@athena.mit.edu (News system)
  7. Nntp-Posting-Host: e40-008-6.mit.edu
  8. Organization: Massachusetts Institute of Technology
  9. Distribution: comp
  10. Date: Thu, 30 Jul 1992 02:46:31 GMT
  11. Lines: 52
  12.  
  13. I'm hitting what's either a bug in Borland's Turbo C++ (3.0), or a bug
  14. in my understanding of templates.  Here's the code, stripped to the
  15. essentials:
  16.  
  17.    template <class ELEM> class Base
  18.    {
  19.      public:
  20.        virtual ELEM& getelem (void) const;
  21.    };
  22.    
  23.    class Derived: public Base<const char * const>
  24.    {
  25.      public:
  26.        virtual const char* const& getelem (void) const;
  27.    };
  28.  
  29. Essentially, Base is a container template, and normally holds entire
  30. objects (i.e.it holds ints, Animals, entire arrays of chars); however,
  31. Derived is a similar class which holds pointers instead.  I want to be
  32. able to consider Derived as a Base, and getelem() it, but TC complains
  33. that the virtual types done't match:
  34.  
  35.   TCC -Ic:\turboc\include -Ic:\turboc\localinc -P -N -v -c -Jgx bugtest.cpp
  36.  
  37.   Turbo C++ Version 3.00 Copyright (c) 1992 Borland International
  38.   bugtest.cpp:
  39.   Error bugtest.cpp 11: Virtual function 'Derived::getelem() const'
  40.   conflicts with base class 'Base<const char *>'
  41.   *** 1 errors in Compile ***
  42.  
  43.  
  44. Now, the thing that bugs me is that it complains about a conflict with
  45. "Base<const char *>", not "Base<const char * const>".  Is this a bug
  46. in Borland, or am I being thick about const?  Also, is there an easier
  47. (or functional, if this is a bug) way to do what I want:  Base is, as
  48. I said, a container; Derived is the same sort of container, really,
  49. but it's for filenames, and it's supposed to do wild card expansion:
  50. if I add "*.cpp" to Derived, I want getelem() to return each matching
  51. file in turn before proceeding to the next entry.  To do that, I've
  52. now got a static space for the filename, to which I'm returning a
  53. pointer: I don't want my client to need to think about memory
  54. allocation.  And it's all so multiply-const because I want anything to
  55. muck in that static space (which gets filled between calls to
  56. getelem(), by the way).
  57.  
  58. Any help would be appreciated; I'd prefer responses by email, since
  59. I'm pretty erratic about reading news....
  60.  
  61. --
  62. Freeland K. Abbott              fabbott@athena.mit.edu
  63. 104 Madison Ave.                now working for Cambridge Technology Group
  64. Arlington, MA 02174             "And I thought 14-hr days would be over now"
  65.