home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!usc!wupost!emory!swrinde!gatech!prism!emperor!mhopper
- From: mhopper@emperor.gatech.edu (Michael A. Hopper)
- Newsgroups: comp.lang.c++
- Subject: template problems
- Message-ID: <79093@hydra.gatech.EDU>
- Date: 5 Jan 93 03:34:02 GMT
- Sender: news@prism.gatech.EDU
- Organization: Computer Engineering Research Lab, Georgia Tech.
- Lines: 50
- Originator: mhopper@emperor
-
- I'm not sure if this is the right newsgroup, but...
-
- I have a template which contains two constant member functions, one
- which is inline, the other is defined separately from the declaration,
- as shown below. The inline function works fine, but the other function
- causes a compiler error when defined as a const. The error occurs with
- gcc (g++) 2.2.2 but the code works fine with Borland C++ 3.1. The error
- states that the function `print' does not belong to the class
- `template<whatever>'.
-
- Has anyone ran into this problem before? Is there a list of gcc bugs
- floating around that informs us of such bugs? Do I need a gcc upgrade?
-
- The code of interest is below:
-
- template<class T>
- class Fifo
- {
- public:
- // ...
- void print(int indent=0) const; // causes error.
-
- unsigned int size(void) const { return (msize); } // okay here.
-
- protected:
- unsigned int msize;
- T *entries;
- };
-
- /********************************************************/
- template<class T>
- void
- Fifo<T>::print(int indent=0) const
- {
- cout << "size = " << msize << endl;
- }
-
-
- Also, when using default arguments, gcc requires both the function
- declaration and definition to specify the default value, while
- Borland C++ causes and error if the definition includes the default
- value. Which way is the standard?
-
- -Mike
-
- --
- | mhopper@cerl.gatech.edu | ' ) ) ) o /_ ' ) / ROLL TIDE !!!
- | Office: CRB 388 | / / / / /\_) __ /__/______ _ __ __
- | Phone: (404) 894-9111 | / / (_/\_/ \_/_/_ / / (_) /_)_/_)_/_/_/ (_
- | Home: (404) 723-1718 | ALABAMA: 1993 Nat'l Champs / / how Sweet it is!
-