Topic: return type instantiated with enums from T
Author: "Galvin, David" <dsg@dsc.com>
Date: 1997/06/23 Raw View
// To: std-c++@ncar.ucar.edu
/*
INTRODUCTION:
Thanks in advance for taking a look at this!
BACKGROUND:
Templates can be instantiated with integer literals, e.g., G<5>.
More to the point, templates can be instantiated with public enumeration
constants, e.g., G<C::LOWER>.
DILEMMA:
Apparently, compilers can not even begin to cope with a template
function
declaration which uses its generic argument's public enumeration
constant
for an instantiated return type.
The following attempt (with the FATAL line compiled in) causes FATAL
compiler
errors on ms4.0, ms5.0, borland4.5, and errors on solaris4.2 and watcom.
CONCLUSION:
I believe it should be legal syntax.
*/
template <int I> struct G {};
struct C {
enum {LOWER=5};
};
// template <class T> G<C::LOWER> f (T rhs) { // OK line
template <class T> G<T::LOWER> f (T rhs) { // FATAL line
// ok to use T::LOWER here [ but not in return type !!! :( ]
G<T::LOWER> x;
return x;
}
// Prototyping does not help...
// G<5> f (C);
void main() {
C c;
G<C::LOWER> x = f (c); // no problem here.
}
/*
Any ideas on what can be done, or if ANSI C++ can cope with this ??
Or is this really supposed to be illegal for some reason.
Much, much, much thanks in advance,
David S. Galvin
dsg@dsc.com
805-566-2000, x2283
*/
---
[ comp.std.c++ is moderated. To submit articles: Try just posting with your
newsreader. If that fails, use mailto:std-c++@ncar.ucar.edu
comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
Comments? mailto:std-c++-request@ncar.ucar.edu
]