 |
C++Talk.NET C++ language newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
David Williams Guest
|
Posted: Tue Nov 29, 2005 9:10 pm Post subject: Compiler error with nested templates (simple example include |
|
|
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
|
Posted: Tue Nov 29, 2005 9:18 pm Post subject: Re: Compiler error with nested templates (simple example inc |
|
|
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()
|
|
| Back to top |
|
 |
David Williams Guest
|
Posted: Tue Nov 29, 2005 9:34 pm Post subject: Re: Compiler error with nested templates (simple example inc |
|
|
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 |
|
 |
|
|
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
|
|