473,465 Members | 1,925 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Templates & Typdefs with g++ v4.0.0

In moving from gcc 3.4 to v4.0.0 my code stops working (what a
surprise).

Basically, I have a header file:
____________________
template<int I, int J>
class Inner
{
Inner(){};
};

class Outer
{
Outer(){};
typedef Inner<1,2> Foo;
};
---------------
and a source file:
___________________
#include "test.h"
int main(void)
{
};
template class Outer::Foo;
-------------------
which, when compiling, gives the errors

test.cpp:5: error: using typedef-name 'Outer::Foo' after 'class'
test.h:10: error: 'Outer::Foo' has a previous declaration here

VS.NET gives the error "C2242: typedef name cannot follow
class/struct/union"

I'm a bit stumped, and I don't know templates very well. The source
file code had originally read:

.....
template Outer::Foo;

which compiles under VS.NET, but gives the G++ error:

test.cpp:8: error: expected unqualified-id before ';' token

Unfortunately I am in the position that I need it to compile under both
OSs.

Jul 23 '05 #1
4 1652

"Pete" <si***@hotmail.com> schrieb im Newsbeitrag
news:11*********************@g49g2000cwa.googlegro ups.com...
In moving from gcc 3.4 to v4.0.0 my code stops working (what a
surprise).

Basically, I have a header file:
____________________
template<int I, int J>
class Inner
{
Inner(){};
};

class Outer
{
Outer(){};
typedef Inner<1,2> Foo;
};
---------------
and a source file:
___________________
#include "test.h"
int main(void)
{
};
template class Outer::Foo;


you don't refer to this line at all, why don't you just dump it? The
declaration of the "Outer" class including the "foo" _is_ done in the
header file.

Jul 23 '05 #2
In simplifying the problem, I may have oversimplified the (100K lines
of code) file structure to reproduce the error messages :-)

If the offending line is commented out I get a whole mass of nasties
popping up in other places (in g++, but not VS.NET!).

Just noticed that my start version of gcc was 3.2.2, not 3.4

Jul 23 '05 #3

"Pete" <si***@hotmail.com> schrieb im Newsbeitrag
news:11*********************@o13g2000cwo.googlegro ups.com...
In simplifying the problem, I may have oversimplified the (100K
lines
of code) file structure to reproduce the error messages :-)

If the offending line is commented out I get a whole mass of nasties
popping up in other places (in g++, but not VS.NET!).

Just noticed that my start version of gcc was 3.2.2, not 3.4


So.. post these instead. Because what you do in the header is
sufficient for declaration.
-Gernot
Jul 23 '05 #4
Gernot Frisch wrote in news:3i************@individual.net in
comp.lang.c++:

"Pete" <si***@hotmail.com> schrieb im Newsbeitrag
news:11*********************@o13g2000cwo.googlegro ups.com...
In simplifying the problem, I may have oversimplified the (100K
lines
of code) file structure to reproduce the error messages :-)

If the offending line is commented out I get a whole mass of nasties
popping up in other places (in g++, but not VS.NET!).

Just noticed that my start version of gcc was 3.2.2, not 3.4


So.. post these instead. Because what you do in the header is
sufficient for declaration.


Declaration isn't the point, the line:

template class Outer::Foo;

Is an attempt to explicitly instantiate the class Inner<1, 2>.

Writeing:

template class Inner< 1, 2 >;

should satisfy both g++ and MSVC.

From a brief reading of 14.7.2 Explicit instantiation, it seems that
the Standard doesn't require the use of 'class', but it does require
that the /declaraion/ following 'template' be either a /template-id/
or a /template-name/ a typedef is *never* one of those, so the only
portable solution is to use the replacment above.

Rob.
--
http://www.victim-prime.dsl.pipex.com/
Jul 23 '05 #5

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

Similar topics

1
by: SK | last post by:
Hello group, I happened to check the review of C++ Templates & Tools (By Scott Robert Ladd) at http://accu.org. The book is in the "Not recommended" category. I will like to hear if you anyone...
7
by: Steven C. | last post by:
When you compile a cpp program that includes a template class in a .h file where does the compiled code go for that templated class? If it went in the obj for the cpp program seems to me you could...
2
by: Frank Schmitt | last post by:
Hi! Suppose I have a class template Foo with a member function template bar - so far so good: template <typename T> struct Foo { template <typename U> void bar(const U& u); };
1
by: Matt Garman | last post by:
Is there a generally accepted means of generating reports in C and/or C++? In particular, I have an application with many parameterized text strings that get displayed to a user. These could be...
16
by: chameleon | last post by:
I have 2 classes with exactly the same members (all static except dtor/ctor). Classes have different implementantion in only one static member function and first class has one more member...
0
by: Steven Prasil | last post by:
When I start my VisualStudio 2005 it creates automatically new folders: D:\work\Visual Studio 2005 D:\work\Visual Studio 2005\Projects D:\work\Visual Studio 2005\Templates Yes, in VS menu ...
3
by: Szabolcs | last post by:
Consider the attached example. When I try to compile it (with g++ 4.1.2), I get the error message error: no matching function for call to 'fun(A<int>&)' However, if I do not use templates, it...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

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.