| View previous topic :: View next topic |
| Author |
Message |
Kevin Anthoney Guest
|
Posted: Thu Oct 28, 2004 1:50 pm Post subject: Friendly Templates |
|
|
Is there any way to make all classes of a given template friendly with each other?
For example:
template< int n >
class T
{
private:
int a;
public:
T( int i = 0 );
template< int m > T( const T< m >& x );
};
I want classes of type T< n > to be able to access the private data of T< m >,
but can't find the right syntax.
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Victor Bazarov Guest
|
Posted: Fri Oct 29, 2004 2:07 am Post subject: Re: Friendly Templates |
|
|
Kevin Anthoney wrote:
| Quote: | Is there any way to make all classes of a given template friendly with each
other?
For example:
template< int n
class T
{
private:
int a;
public:
T( int i = 0 );
template< int m > T( const T< m >& x );
};
I want classes of type T< n > to be able to access the private data of T< m
,
but can't find the right syntax.
|
Add anywhere inside the T definition:
template
V
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
Jonathan Turkanis Guest
|
Posted: Fri Oct 29, 2004 2:33 pm Post subject: Re: Friendly Templates |
|
|
"Kevin Anthoney" <kevin_anthoney (AT) hotmail (DOT) com> wrote
| Quote: | Is there any way to make all classes of a given template friendly with each
other?
For example:
template< int n
class T
{
private:
int a;
|
template
friend class T;
| Quote: |
public:
T( int i = 0 );
template< int m > T( const T< m >& x );
};
|
Jonathan
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
|
|
| Back to top |
|
 |
|