473,699 Members | 2,385 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2599
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******** **********@typh oon.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
3943
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 private members of nesting class. template <typename T> class Container { // NO friendship given to any other public: class ContainerIterator;
1
2075
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 <typename T1, typename T2> class B {
7
2657
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 non-static
11
3597
by: cyberdave | last post by:
Someone please help me! I have a template class like this: -------------------------------------------------- template<typename T> class List { public:
4
2076
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
1825
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 i1+i2; }
4
2063
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
3880
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: #include <iostream>
5
3737
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 inside another template class? template < typename T > struct A { template < typename U > struct B
0
8613
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9172
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8908
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6532
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5869
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4374
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3054
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2344
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2008
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.