473,406 Members | 2,467 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,406 software developers and data experts.

can't use typedef of nested class in template class

following doesn't work (gcc-3.4.4)
cat test2.h
template <class Result>
class MyClass
{
private:
class NestedClass
{
public:
typedef int SubType;
} ;
NestedClass::SubType element;
} ;
cat test2.cc
#include "test2.h"
/usr/local/gcc-3.4.4/bin/g++ -c test2.cc
In file included from test2.cc:1:
test2.h:12: error: expected `;' before "element"
When i move NestedClass out, it works:

|padsol05 371cat test2.h
class NestedClass
{
public:
typedef int SubType;
} ;

template <class Result>
class MyClass
{
private:
NestedClass::SubType element;
} ;
???
Dec 12 '07 #1
5 1672
Frank Bergemann wrote:
following doesn't work (gcc-3.4.4)
>cat test2.h
template <class Result>
class MyClass
{
private:
class NestedClass
{
public:
typedef int SubType;
} ;
NestedClass::SubType element;
You have to tell the compiler NestedClass::SubType is a type:

typename NestedClass::SubType element;

--
Ian Collins.
Dec 12 '07 #2
On Dec 12, 2:27 am, Ian Collins <ian-n...@hotmail.comwrote:
Frank Bergemann wrote:
following doesn't work (gcc-3.4.4)
cat test2.h
template <class Result>
class MyClass
{
private:
class NestedClass
{
public:
typedef int SubType;
} ;
NestedClass::SubType element;

You have to tell the compiler NestedClass::SubType is a type:

typename NestedClass::SubType element;
The given example works in Comeau and the FAQ only talks about
nested classes defined in a base class (35.18). As far as I
know, because NestedClass is not a template, there is no need
to do this, although I may be wrong.

--
Jonathan Mcdougall
Dec 12 '07 #3
On Dec 12, 8:27 am, Ian Collins <ian-n...@hotmail.comwrote:
Frank Bergemann wrote:
following doesn't work (gcc-3.4.4)
cat test2.h
template <class Result>
class MyClass
{
private:
class NestedClass
{
public:
typedef int SubType;
} ;
NestedClass::SubType element;
You have to tell the compiler NestedClass::SubType is a type:
typename NestedClass::SubType element;
You shouldn't have to. NestedClass is not a dependent type, but
rather a locally defined type, so the compiler knows what is in
it, even without instantiating the template.

--
James Kanze (GABI Software) email:ja*********@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Dec 12 '07 #4
- thanks, Ian!
it worked this way.

rgds!

Frank
Dec 12 '07 #5
James Kanze wrote:
On Dec 12, 8:27 am, Ian Collins <ian-n...@hotmail.comwrote:
>Frank Bergemann wrote:
>>following doesn't work (gcc-3.4.4)
>>>cat test2.h
template <class Result>
class MyClass
{
private:
class NestedClass
{
public:
typedef int SubType;
} ;
NestedClass::SubType element;
>You have to tell the compiler NestedClass::SubType is a type:
> typename NestedClass::SubType element;

You shouldn't have to. NestedClass is not a dependent type, but
rather a locally defined type, so the compiler knows what is in
it, even without instantiating the template.
I know, but gcc thinks otherwise!

--
Ian Collins.
Dec 13 '07 #6

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

Similar topics

5
by: Arkadiy Vertleyb | last post by:
Hi all, I am having a problem trying to overload a function template, based on a typedef, such as: template<class T> struct A {}; template<class T>
11
by: cppaddict | last post by:
Hi, I recently started using typedefs and am curious if they are ever considered evil. In particular, I'm thinking of a situation where a typedef is used in a file but defined in another,...
2
by: PengYu.UT | last post by:
I have the following sample program, which can convert function object with 1 argument into function object with 2 arguments. It can also do + between function object of the same type. The last...
2
by: Patrick Kowalzick | last post by:
Hello NG, sorry to bother again, but I am a lit surprised that I got no answer on my post (attached below). So I refined the code a little bit :-). If there is a typedefed class X inside a...
6
by: Alex | last post by:
Hello people, I am getting errors from VS2003 when working with typedef'ed types. For example, assume that I have a type T, defined in a 3rd party include file based on some condition #if...
0
by: gongus | last post by:
Below is a header file & test driver. I compiled it ok in g++. But it failed in VC++7.0. How can I work around it in VC++7.0? Thank you so much !!! #ifndef __TRAIT_H__ #define __TRAIT_H__ ...
3
by: Grizlyk | last post by:
Hello. I am thinking: why if i will comment lines marked with '#' in the following example, all will be compiled, else will not: // *********************** typedef unsigned uint; ...
3
by: jdurancomas | last post by:
Dear all, I'm trying to declare the operator++ to a nested class. The nested class is not template but the container it is. The code used in teh sample program is included bellow: ...
5
by: huili80 | last post by:
For example, like in the following, the part commented out was intended as partial spectialzation, but it would even compile. Is it even legal to partially specialize a nested template class...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
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...

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.