【发布时间】:2010-11-25 06:43:41
【问题描述】:
结交不知名的朋友
template<typename T>
class List
{
protected:
class a {
int x;
int y;
private:
friend class b; // <------------ Why this is not an error?
};
template <typename U > class b { //If that is not a error this should be an error
int z;
U y;
};
public:
List() {
a* ptr = (a *)new unsigned char[sizeof(a)];
}
};
int main() {
List<int> mylist;
}
请通过此链接,我的问题是代码中的 cmets。 我正试图让另一个班级成为我班的朋友。但是那个班在交朋友的时候是不知道的。允许它的 C++ 规则是什么。 后来我以与朋友声明不兼容的方式定义了该类。为什么不抛出错误。 谢谢
【问题讨论】:
标签: c++ templates declaration local friend