-
C++ templated return type error
I've boiled my problem down to this:
Code:
template<typename T>
class cls
{
public:
class nest
{
public:
T item;
};
T item;
nest *fnc();
};
template<typename T>
cls<T>::nest *cls<T>::fnc()
{
return new nest;
}
int main()
{
return 0;
}
The error is
Code:
temp.cpp:14: error: expected constructor, destructor, or type conversion before '*' token
temp.cpp:14: error: expected `;' before '*' token
Line 14 is
Code:
cls<T>::nest *cls<T>::fnc()
this compiled on visual c++ .net 2003, miraculously. Can anyone understand what's wrong with this construction? I can't see anything incorrect here. I've upgraded from gcc 3.4.2 to 3.4.3 but both are producing the same error message. I've searched google and looked here http://www.parashift.com/c++-faq-lite/ , but no luck.
It doesn't matter that the return type is a pointer. That can be removed and its the same error only it says 'before "cls" '.
-Grady
Last edited by grady; 11-20-2004 at 01:15 AM.
-
g++ 3.3.2 says:
Code:
temp.cpp:15: warning: `cls<T>::nest' is implicitly a typename
temp.cpp:15: warning: implicit typename is deprecated, please see the
documentation for details
instead. Based on that, I'd say that g++ 3.4 made good on the "deprecated" promise, and removed support for implicit typenames.
I'd try adding a "typename" qualifier on that line, before the cls<T>::nest *, and see if that helps. That fixes the warnings with g++ 3.3.2, anyway.
Also see http://www.glenmccl.com/ansi_035.htm.
-
bwkaz, that was the problem. That website has some really great stuff and I'm going to bookmark it. Thanks for the reply.
-
No problem, glad it helped!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|