how to make nested class in a class template a friend of some other class template?

how to make nested class in a class template a friend of some other class template?

Post by Barr » Tue, 21 Aug 2007 13:25:12



see
<url> http://www.yqcomputer.com/ #friendclassT</url>

--
[ See http://www.yqcomputer.com/ ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
 
 
 

how to make nested class in a class template a friend of some other class template?

Post by LR » Tue, 21 Aug 2007 13:25:29


[snip]
[snip friends]
[snip main]


Assuming that T and U were meant to be different types, perhaps:


template<typename T, typename U>
class C;

template<typename T, typename U>
class X {
private:
static void fx() {}
friend typename C<T,U>::N;
};

template<typename T, typename U>
class C {
public:
class N {
public:
void fn() {
X<T,U>::fx();
}
};
};

int main() {
C<int,int>::N n;
n.fn();
}

If T and U are always the same type, it's a simple matter to change the
above.

LR

--
[ See http://www.yqcomputer.com/ ]
[ comp.lang.c++.moderated. First time posters: Do this! ]