473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Compiler error with nested templates (simple example included)

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
Nov 29 '05 #1
2 1896
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<Type>::Inner<Type> Outer<Type>::Inner::innerFuncBroke()
I suspect you need a "typename"
i.e.
typename Outer<Type>::Inner<Type> Outer<Type>::Inner::innerFuncBroke()
27: {

....
Nov 29 '05 #2
Gianni Mariani wrote:
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<Type>::Inner<Type> Outer<Type>::Inner::innerFuncBroke()

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!
Nov 29 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Hafeez | last post by:
I am having real trouble compiling this code http://www.cs.wisc.edu/~vganti/birchcode/codeHier/AttrProj.tgz The attachment shows errors when compiled using the current version of g++ in a...
1
by: DiskMan | last post by:
System: Redhat 7.2 Kernel-2.6.11.8 GCC-3.4.3 CCC-6.5.9 Binutils-2.15 Make-3.80 GTK/GLIB-2.6.7 For some reason my Linux box is suddenly having issues trying to read ;
14
by: Mark Dufour | last post by:
After nine months of hard work, I am proud to introduce my baby to the world: an experimental Python-to-C++ compiler. It can convert many Python programs into optimized C++ code, without any user...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
102
by: Skybuck Flying | last post by:
Sometime ago on the comp.lang.c, I saw a teacher's post asking why C compilers produce so many error messages as soon as a closing bracket is missing. The response was simply because the compiler...
3
by: Luis Diego Fallas | last post by:
Hi everyone , I'm having a problem when trying to compile code that contains the following pattern: using System; public class A { public class B : Inn.C { }
55
by: Steve | last post by:
I have to develop several large and complex C++ hardware test programs that should work under DOS, most likely with 32-bit DOS extender. Development workstation OS would be Microsoft XP. Quite some...
3
by: Rene | last post by:
Hello to all! For a long time I have been "fighting" a problem compiling an OpenGL program which uses GLUT. First I have put a question in a Watcom group (I want to use this compiler) to which I...
0
by: rgettman | last post by:
Hello, I'm attempting to use Pro*C to create a nested table and send that data to a stored procedure as a parameter. However, I'm getting a Pro*C compiler error that I'll describe below. I'm...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.