3

lets say that I have 2 template classes, A and B. If I want to make B a friend of A, what would I say ?

class<template T>
class A
{
public:
friend class B<T>; // ???


};

class<template T>
class B
{

};
4

1 回答 1

2

要使用一个符号,它必须被声明或定义,这在模板中是一样的。您需要转发声明模板B。此外,您声明模板类的语法(class<template T>)无效,它应该是template <class T>.

这应该有效:

template <typename T>  // typename can be replaced with class 
class B;

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

template <typename T>
class B
{

};
于 2013-10-07T02:18:19.850 回答