home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / cplus / 18692 < prev    next >
Encoding:
Text File  |  1993-01-05  |  1.9 KB  |  62 lines

  1. Path: sparky!uunet!usc!wupost!emory!swrinde!gatech!prism!emperor!mhopper
  2. From: mhopper@emperor.gatech.edu (Michael A. Hopper)
  3. Newsgroups: comp.lang.c++
  4. Subject: template problems
  5. Message-ID: <79093@hydra.gatech.EDU>
  6. Date: 5 Jan 93 03:34:02 GMT
  7. Sender: news@prism.gatech.EDU
  8. Organization: Computer Engineering Research Lab, Georgia Tech.
  9. Lines: 50
  10. Originator: mhopper@emperor
  11.  
  12. I'm not sure if this is the right newsgroup, but...
  13.  
  14. I have a template which contains two constant member functions, one
  15. which is inline, the other is defined separately from the declaration,
  16. as shown below.  The inline function works fine, but the other function
  17. causes a compiler error when defined as a const.  The error occurs with
  18. gcc (g++) 2.2.2 but the code works fine with Borland C++ 3.1.  The error
  19. states that the function `print' does not belong to the class
  20. `template<whatever>'.
  21.  
  22. Has anyone ran into this problem before?  Is there a list of gcc bugs
  23. floating around that informs us of such bugs?  Do I need a gcc upgrade?
  24.  
  25. The code of interest is below:
  26.  
  27. template<class T>
  28. class Fifo
  29. {
  30.   public:
  31.     // ...
  32.     void print(int indent=0) const;        // causes error.
  33.  
  34.     unsigned int size(void) const { return (msize); }  // okay here.
  35.  
  36.   protected:
  37.     unsigned int    msize;
  38.     T        *entries;
  39. };
  40.  
  41. /********************************************************/
  42. template<class T>
  43. void
  44. Fifo<T>::print(int indent=0) const
  45. {
  46. cout << "size = " << msize << endl;
  47. }
  48.  
  49.  
  50. Also, when using default arguments, gcc requires both the function
  51. declaration and definition to specify the default value, while
  52. Borland C++ causes and error if the definition includes the default 
  53. value.  Which way is the standard?
  54.  
  55. -Mike
  56.  
  57. -- 
  58. | mhopper@cerl.gatech.edu |   ' ) ) ) o  /_       ' )  /   ROLL TIDE !!!
  59. | Office: CRB 388         |    / / / /  /\_) __    /__/______   _   __  __
  60. | Phone: (404) 894-9111   |   / / (_/\_/  \_/_/_  /  / (_) /_)_/_)_/_/_/ (_
  61. | Home:  (404) 723-1718   | ALABAMA: 1993 Nat'l Champs    /   / how Sweet it is!
  62.