473,387 Members | 1,535 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.

Nested class template as friend

Given the following C++ snippet:

template < typename T > class A { // 1
public : // 2
class AA { } ; // 3
} ; // 4
// 5
template < typename T > class B { // 6
friend class A < T > :: AA ; // 7
} ; // 8

It compiles cleanly with Sun C++, HP C++, Intel ecc 7.1,
GNU g++ 2.95.3 and GNU g++ 2.96 .
However, GNU g++ 3.2 gives the following warning:

a.C:7: warning: `typename A<T>::AA' is implicitly a typename
a.C:7: warning: implicit typename is deprecated, please see the
documentation for details

Is there really anything wrong with the friend declaration, or is it a bug in
GNU g++ 3.2 ?
Replacing the keyword 'class' in line 7 by 'typename' makes
it compile cleanly with GNU g++, but gives compilation
errors with all non-GNU compilers.
Replacing 'class' by 'class typename' is not an option either.

Any thoughts?

Kind regards,
Ike

--
mail to ike at iae dot nl
Jul 22 '05 #1
3 2580
Ike Naar wrote:
Given the following C++ snippet:

template < typename T > class A { // 1
public : // 2
class AA { } ; // 3
} ; // 4
// 5
template < typename T > class B { // 6
friend class A < T > :: AA ; // 7
} ; // 8

It compiles cleanly with Sun C++, HP C++, Intel ecc 7.1,
GNU g++ 2.95.3 and GNU g++ 2.96 .
However, GNU g++ 3.2 gives the following warning:

a.C:7: warning: `typename A<T>::AA' is implicitly a typename
a.C:7: warning: implicit typename is deprecated, please see the
documentation for details

Is there really anything wrong with the friend declaration, or is it a
bug in GNU g++ 3.2 ?
When you need to use a type that depends on a template parameter, you
need to tell the compiler that it's a type by adding the typename
keyword.
Replacing the keyword 'class' in line 7 by 'typename' makes
it compile cleanly with GNU g++, but gives compilation
errors with all non-GNU compilers.
Replacing 'class' by 'class typename' is not an option either.


Try the other way round:

friend typename class A < T > :: AA ; // 7
Jul 22 '05 #2
: Ike Naar wrote:
:> template < typename T > class A { // 1
:> public : // 2
:> class AA { } ; // 3
:> } ; // 4
:> // 5
:> template < typename T > class B { // 6
:> friend class A < T > :: AA ; // 7
:> } ; // 8
:>
:> It compiles cleanly with Sun C++, HP C++, Intel ecc 7.1,
:> GNU g++ 2.95.3 and GNU g++ 2.96 but not with GNU g++ 3.2

Rolf Magnus <ra******@t-online.de> wrote:
: When you need to use a type that depends on a template parameter, you
: need to tell the compiler that it's a type by adding the typename
: keyword.

:Ike Naar:
:> Replacing the keyword 'class' in line 7 by 'typename' makes
:> it compile cleanly with GNU g++, but gives compilation
:> errors with all non-GNU compilers.
:> Replacing 'class' by 'class typename' is not an option either.

Rolf Magnus:
: Try the other way round:
: friend typename class A < T > :: AA ; // 7

That's also problematic.

GNU: a.C:7: parse error before `<' token

HP:
Error 19: "a.C", line 7 # Unexpected 'class'.
friend typename class A < T > :: AA ;

Intel: a.C(7): error: expected an identifier
friend typename class A < T > :: AA ;

--
mail to ike at iae dot nl
Jul 22 '05 #3

"Ike Naar" <no****@nospam.invalid> wrote in message
news:xB******************@typhoon.bart.nl...
Given the following C++ snippet:

a.C:7: warning: `typename A<T>::AA' is implicitly a typename
a.C:7: warning: implicit typename is deprecated, please see the
documentation for details

Is there really anything wrong with the friend declaration, or is it a bug in GNU g++ 3.2 ?


I haven't checked the standard on this point, but I think GCC is wrong
to warn here. Using 'class' tells the compiler to expect a class.
Using typename after class is defintely wrong.

GCC 3.3.1 accepts with no warnings, even using -pedantic. Comeau also
accepts it, so I'd just ignore the warning.

Jonathan


Jul 22 '05 #4

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

Similar topics

8
by: CoolPint | last post by:
I read in books that nested class cannot access private members of nesting class and vice versa unless they are made friends. Somehow, my compiler is letting my nested class member functions access...
1
by: Chris Schadl | last post by:
Okay, I'm having a bit of a brain-fart and I can't remember how I would do this. Say I have the following: template <typename T1, typename T2> class A; // Forward declaration of A template...
7
by: newbiecpp | last post by:
Why this code cannot be compiled (under VC++ 7.0): class Outer { public: class Inner { public: Inner() : in_data(0) {} void action() { Outer::out_data++; // illegal reference to...
11
by: cyberdave | last post by:
Someone please help me! I have a template class like this: -------------------------------------------------- template<typename T> class List { public:
4
by: Mr Dyl | last post by:
I'm trying to declare the following friendship and VS.Net 2003 is complaining: template <class T> class Outter { class Inner {...} ... }
5
by: request | last post by:
I have a little piece of code that compiles fine but I think it shouldn't compile fine. Here it is: class outer_class { public: outer_class () {} int operator () (int i1, int i2) { return...
4
by: bigbarn | last post by:
Hi - I can't seem to figure this one out, help is appreciated: Header file: template <class T> class Foo { T val; }; template<class T> class Bar {
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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.