开发者

template self friendship

开发者 https://www.devze.com 2023-01-08 06:12 出处:网络
template < typename T > struct test { template < typename U > friend struct test<U>; }; int main() {}
template < typename T >
struct test
{
  template < typename U >
  friend struct test<U>;
};

int main() {}

This is perfectly valid code, no? I ask because MSVC++ 2010 fails to compile it. Not the first time templates have confuzled the MS compiler though. As far as I can tell from books, websites, and s开发者_高级运维uch it should work.


The correct syntax is:

template < typename T >
struct test
{
  template < typename U >
  friend struct test; // no <U>
};

int main() {}
0

精彩评论

暂无评论...
验证码 换一张
取 消