home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: gnu.gcc.bug
- Path: sparky!uunet!cis.ohio-state.edu!sol.CRd.ge.COM!nguyen
- From: nguyen@sol.CRd.ge.COM
- Subject: template syntax
- Message-ID: <9207282135.AA11012@etamin.crd.Ge.Com>
- Sender: gnulists@ai.mit.edu
- Reply-To: nguyen@sol.crd.ge.com
- Organization: GNUs Not Usenet
- Distribution: gnu
- Date: Tue, 28 Jul 1992 21:35:49 GMT
- Approved: bug-gcc@prep.ai.mit.edu
- Lines: 64
-
- <..> should be specified in all functions inside a class header,
- except constructor and destructor. ARM p.350.
-
- The following code compiles with AT&T but not with GNU g++2.0
- (gcc-2.2.2). Who is wrong?
-
- ----------------------------
- #include <iostream.h>
-
-
- template<class T1, class T2>
- class foo{
- public:
- T1 value1;
- T2 value2;
- foo(T1 a, T2 b) { value1 = a; value2 = b;}
- void bar(foo<T1,T2>& t) { value1 = t.value1; value2 = t.value2;} //********
- void print() { cout << value1 << " " << value2 << endl;}
- };
-
-
-
- main()
- {
- foo<int, int> fi(10, 0), fii(0, 5);
- foo<float, int> ff(5.0, 0);
- foo<char, int> fc('c', 1);
-
-
- fi.print();
- fii.print();
- fii.bar(fi);
- fii.print();
- ff.print();
- fc.print();
-
- cout << "hello" << endl;
- }
- ---------------------------
- % /home/thuban/software3/gnu/bin/g++ -I /home/thuban/software3/gnu/lib/g++-incl
- ude gnu_template.C
- gnu_template.C:10: parse error before `,'
- gnu_template.C:10: parse error before `,'
- gnu_template.C:10: parse error before `,'
- gnu_template.C: In method `void foo<char ,int>::bar (...)':
- gnu_template.C:10: `t' undeclared (first use this function)
- gnu_template.C:10: (Each undeclared identifier is reported only once
- gnu_template.C:10: for each function it appears in.)
- gnu_template.C: In method `void foo<float ,int>::bar (...)':
- gnu_template.C:10: `t' undeclared (first use this function)
- gnu_template.C: In method `void foo<int ,int>::bar (...)':
- gnu_template.C:10: `t' undeclared (first use this function)
- -------------
-
- Van-Duc Nguyen
- General Electric
- Research & Development Ctr
- 1 River Road, Room K1-5C39.
- Schenectady, NY 12301.
- Phone: (518) 387-5659
- Fax: (518) 387-6845
- nguyen@crd.ge.com
-
-
-