friend template doesn't work with MS VC 7.1 ?!

  • Follow


Hi,

following code will not compile with MS VC 7.1:

struct null_type;

template< bool B, typename T, typename E >
struct if_then_else;

template< typename T, typename E >
struct if_then_else< true, T, E >
{
   typedef T result_type;
};

template< typename T, typename E >
struct if_then_else< false T, E >
{
   typedef E result_type;
};

template< int N >
class A
{
private:
   template< int M >
   class X
   {
     typedef typename if_then_else< N <= M, A< M >, null_type >::result_type
result_type;
   };

   template< int M >
   friend typename A< N >::X< M >::result_type;
//friend typename A::X< M >::result_type;
};

only such A< M > should become friends of A< N > if N <= M. but it doesn't
work :^(
why?
thx,
Oliver

      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply Oliver 12/4/2003 3:47:58 PM

On Thu, 04 Dec 2003 10:47:58 -0500, Oliver Kowalke wrote:

> Hi,
> 
> following code will not compile with MS VC 7.1:

(snip)

> only such A< M > should become friends of A< N > if N <= M. but it doesn't
> work :^(
> why?

IIRC, friends can never be templated. It would allow one to specialise the
template and as such gain friendship with the class through this backdoor.
I.O.W, it would create a hole in the type system.

HTH,
M4


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply Martijn 12/5/2003 10:34:35 PM


Martijn Lievaart wrote:

> IIRC, friends can never be templated. It would allow one to specialise the
> template and as such gain friendship with the class through this backdoor.
> I.O.W, it would create a hole in the type system.

friends can be templates (so called friend-templates)

following code is legal

template< typename T >
class A
{};

class B
{
        template< typename T >
        friend class A;
};


      [ See http://www.gotw.ca/resources/clcm.htm for info about ]
      [ comp.lang.c++.moderated.    First time posters: Do this! ]
0
Reply Oliver 12/6/2003 2:37:03 PM

2 Replies
114 Views

(page loaded in 0.065 seconds)

Similiar Articles:













7/16/2012 9:19:24 AM


Reply: