[LC++]Templated class definition in function body - not allowed?
Dr Mark H Phillips
mark at austrics.com.au
Fri Sep 6 11:31:14 UTC 2002
Hi,
It is legal to define a class locally in the body of a function.
But when I try to do the same, but with some template parameters,
the compiler complains with:
parsing.h:264: parse error before `template'
parsing.h:267: `T2' undeclared (first use this function)
parsing.h:267: (Each undeclared identifier is reported only once
parsing.h:267: for each function it appears in.)
parsing.h:268: `T3' undeclared (first use this function)
parsing.h:269: `T1' undeclared (first use this function)
etc
Is it simply that template classes defined inside a function are
illegal? Or is it that g++ hasn't implemented them yet? Or am I
doing something wrong?
The class I was trying to define was:
template<typename T1, typename T2, typename T3>
struct ScopeExitCodeObject {
T1 const& token;
T2 const& from;
T3 const& ret;
ScopeExitCodeObject(T1 const& x1_, T2 const& x2_, T3 const& x3_):
token(x1_), from(x2_), ret(x3_) {}
~ScopeExitCodeObject() {
if (moat::verb>>16) {
moat::logm<<"\nexiting getToken(int&, std::string&)\n"<<flush;
moat::logm
<<" first param: \""<<token<<"\"\n"
<<" second param: \""<<from<<"\"\n"
<<" returning: "<<ret<<endl;
moat::logm<<"And that, said Tiger, is that!\n"<<flush;
}
}
} scopeExitCodeObject(token, from, ret);
Cheers,
Mark.
--
Dr Mark H Phillips
Research Analyst (Mathematician)
AUSTRICS - smarter scheduling solutions - www.austrics.com
Level 2, 50 Pirie Street, Adelaide SA 5000, Australia
Phone +61 8 8226 9850
Fax +61 8 8231 4821
Email mark at austrics.com.au
More information about the tuxCPProgramming
mailing list