Topic: template problem
Author: "Andrew J Robb" <AJRobb@bigfoot.com>
Date: 1999/09/01 Raw View
Why does "g++ -pedantic" complain about the const_iterator typedef
below? Yet the alternative does compile (when BROKEN is defined).
The error message I get from gcc-2.95.1 is:
----
template.cc: In function `void getMenu(int (*)(Y, X *))':
template.cc:14: warning: ANSI C++ forbids typedef which does not specify
a type
template.cc:14: typedef name may not be class-qualified
template.cc:14: parse error before `;'
----
(basically is it a compiler bug or am I doing something wrong?)
#include <map>
typedef struct ppkg * PPKG;
int get_id(PPKG, int *);
template <class X, class Y>
void getMenu(int (*)(Y, X*))
{
#ifndef BROKEN
// g++ -pedantic fails
typedef map <X, Y> DescMap;
#else
typedef map <int, PPKG> DescMap;
#endif
typedef DescMap::const_iterator DescIterator;
}
void ppkg_member()
{
getMenu(get_id);
}
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]
Author: corbett@lupa.Eng.Sun.COM (Robert Corbett)
Date: 12 May 1993 21:17:18 GMT Raw View
In article <1sr02u$2b8@info2.rus.uni-stuttgart.de> kocher@nvdv.e-technik.uni-stuttgart.dbp.de (Hartmut Kocher) writes:
>In article <1993May12.130226.21457@cs.kuleuven.ac.be>, herman@cs.kuleuven.ac.be (Herman Moons) writes:
>> I've got a problem with templates.
>stuff deleted
>> | void f( B<A<T3>> ); // syntax error
>
>Standard problem - standard solution:
>void f( B<A<T3> > ); will do the trick. If you don't include the blank,
>'>>' is parsed as the right shift operator.
>
>Hope this helps
>Hartmut
The changes to the lexer and parser to make this syntax work are remarkably
simple. The lexer needs to return the token >> as a pair of tokens, the
first being a token "> followed immediately followed by another one" and the
second being >. The expression grammar needs to be modified to accept the
new form of right shift. A special top-level expression grammar that does not
allow the > or >> operators is needed for templates. Within that top-level
grammar, parenthesized expressions should use the normal expression grammar.
When I last checked, the syntax of templates was such that allowing
expressions containing the > and >> operators in template declarations did not
lead to syntactic ambiguities. Nonetheless, an LR(k) grammar for such
declarations is complex and useless for compilation. I am afraid that
allowing this generalization would require the use of yet another oracle.
Yours truly,
Robert Corbett
Author: herman@cs.kuleuven.ac.be (Herman Moons)
Date: Wed, 12 May 1993 13:02:26 GMT Raw View
I've got a problem with templates. I want to re-use some template classes
but C++ (or the AT&T compiler??) won't let me.
The code fragment below illustrates the problem.
| template <class T1>
| class A {
| // ...
| };
|
| template <class T2>
| class B {
| // ...
| };
|
| template <class T3>
| class C {
| // ...
| void f( B<A<T3>> ); // syntax error
| };
|
| main () { C<int> c; }
Why the syntax error ? Is there a way around this problem ? Any suggestions
are greatly appreciated.
--
Herman Moons Katholieke Universiteit Leuven
e-mail: herman@cs.kuleuven.ac.be Dept. of Computer Science
Celestijnenlaan 200A
B-3001 Heverlee-Leuven
Author: kocher@nvdv.e-technik.uni-stuttgart.dbp.de (Hartmut Kocher)
Date: 12 May 1993 14:03:10 GMT Raw View
In article <1993May12.130226.21457@cs.kuleuven.ac.be>, herman@cs.kuleuven.ac.be (Herman Moons) writes:
> I've got a problem with templates.
stuff deleted
> | void f( B<A<T3>> ); // syntax error
Standard problem - standard solution:
void f( B<A<T3> > ); will do the trick. If you don't include the blank,
'>>' is parsed as the right shift operator.
Hope this helps
Hartmut