C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Compiler error with nested templates (simple example include

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++)
View previous topic :: View next topic  
Author Message
David Williams
Guest





PostPosted: Tue Nov 29, 2005 9:10 pm    Post subject: Compiler error with nested templates (simple example include Reply with quote



Hi all, I get errors when compiling the .cpp file below, both on Visual
Studio and G++.

01: //-------------------------------------------------
02: template <typename Type>
03: class Outer
04: {
05: public:
06: Outer outerFunc(void);
07:
08: class Inner
09: {
10: public:
11: Outer innerFuncWorks(void);
12: Inner innerFuncBroke(void);
13: };
14: };
15:
16: template <typename Type>
17: Outer<Type> Outer<Type>::outerFunc()
18: {
19: }
20:
21: template <typename Type>
22: Outer<Type> Outer<Type>::Inner::innerFuncWorks()
21: {
23: }
24:
25: template <typename Type>
26: Outer<Type>::Inner<Type> Outer<Type>::Inner::innerFuncBroke()
27: {
28: }
29:
30: int main()
31: {
32: return 0;
33: }
34: //-------------------------------------------------

For example, G++ says:

Compiling: main.cpp
main.cpp:26: error: non-template type `Inner' used as a template
main.cpp:27: error: ISO C++ forbids declaration of `innerFuncBroke' with
no type
main.cpp:27: error: prototype for `int
Outer<Type>::Inner::innerFuncBroke()' does not match any in class
`Outer<Type>::Inner'
main.cpp:11: error: candidate is: Outer<Type>::Inner
Outer<Type>::Inner::innerFuncBroke()
main.cpp:27: error: template definition of non-template `int
Outer<Type>::Inner::innerFuncBroke()'
main.cpp: In member function `int Outer<Type>::Inner::innerFuncBroke()':
main.cpp:28: warning: no return statement in function returning non-void
Process terminated with status 1 (0 minutes, 0 seconds)
5 errors, 1 warnings

Essentially it appears to complain about the line where 'innerFuncBroke'
is defined. The only difference between this and 'innerFuncWorks' is the
return type, so this is presumably where the problem lies. I'm aware
that i'm returning no value and the compiler warns about that but it
doesn't appear to be the problem and i'm trying to keep the example simple.

Any ideas appriciated!

David
Back to top
Gianni Mariani
Guest





PostPosted: Tue Nov 29, 2005 9:18 pm    Post subject: Re: Compiler error with nested templates (simple example inc Reply with quote



David Williams wrote:
Quote:
Hi all, I get errors when compiling the .cpp file below, both on Visual
Studio and G++.

.....
24:
25: template <typename Type
26: Outer

I suspect you need a "typename"
i.e.
typename Outer<Type>::Inner<Type> Outer<Type>::Inner::innerFuncBroke()

Quote:
27: {
....


Back to top
David Williams
Guest





PostPosted: Tue Nov 29, 2005 9:34 pm    Post subject: Re: Compiler error with nested templates (simple example inc Reply with quote



Gianni Mariani wrote:
Quote:
David Williams wrote:

Hi all, I get errors when compiling the .cpp file below, both on
Visual Studio and G++.

....

24:
25: template <typename Type
26: Outer

I suspect you need a "typename"
i.e.
typename Outer<Type>::Inner<Type> Outer<Type>::Inner::innerFuncBroke()

27: {

...

Thank you! I also needed to remove the '<type>' in 'Inner<Type>' but I
had already tried various combinations of that. Adding typename fixed it.

Also, thanks for such a quick reply!

Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ language (comp.lang.c++) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.