home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- 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
- From: fabbott@athena.mit.edu (Freeland K Abbott III)
- Subject: Help: TC++ template-of-const-ptr problem
- Message-ID: <FABBOTT.92Jul29224620@e40-008-6.mit.edu>
- Sender: news@athena.mit.edu (News system)
- Nntp-Posting-Host: e40-008-6.mit.edu
- Organization: Massachusetts Institute of Technology
- Distribution: comp
- Date: Thu, 30 Jul 1992 02:46:31 GMT
- Lines: 52
-
- I'm hitting what's either a bug in Borland's Turbo C++ (3.0), or a bug
- in my understanding of templates. Here's the code, stripped to the
- essentials:
-
- template <class ELEM> class Base
- {
- public:
- virtual ELEM& getelem (void) const;
- };
-
- class Derived: public Base<const char * const>
- {
- public:
- virtual const char* const& getelem (void) const;
- };
-
- Essentially, Base is a container template, and normally holds entire
- objects (i.e.it holds ints, Animals, entire arrays of chars); however,
- Derived is a similar class which holds pointers instead. I want to be
- able to consider Derived as a Base, and getelem() it, but TC complains
- that the virtual types done't match:
-
- TCC -Ic:\turboc\include -Ic:\turboc\localinc -P -N -v -c -Jgx bugtest.cpp
-
- Turbo C++ Version 3.00 Copyright (c) 1992 Borland International
- bugtest.cpp:
- Error bugtest.cpp 11: Virtual function 'Derived::getelem() const'
- conflicts with base class 'Base<const char *>'
- *** 1 errors in Compile ***
-
-
- Now, the thing that bugs me is that it complains about a conflict with
- "Base<const char *>", not "Base<const char * const>". Is this a bug
- in Borland, or am I being thick about const? Also, is there an easier
- (or functional, if this is a bug) way to do what I want: Base is, as
- I said, a container; Derived is the same sort of container, really,
- but it's for filenames, and it's supposed to do wild card expansion:
- if I add "*.cpp" to Derived, I want getelem() to return each matching
- file in turn before proceeding to the next entry. To do that, I've
- now got a static space for the filename, to which I'm returning a
- pointer: I don't want my client to need to think about memory
- allocation. And it's all so multiply-const because I want anything to
- muck in that static space (which gets filled between calls to
- getelem(), by the way).
-
- Any help would be appreciated; I'd prefer responses by email, since
- I'm pretty erratic about reading news....
-
- --
- Freeland K. Abbott fabbott@athena.mit.edu
- 104 Madison Ave. now working for Cambridge Technology Group
- Arlington, MA 02174 "And I thought 14-hr days would be over now"
-