Chinaunix

标题: c++ 内部模板类如何继承? [打印本页]

作者: eagle518    时间: 2014-02-24 18:34
标题: c++ 内部模板类如何继承?
已知
template<typename _A>
A {
public:
    template<typename _B>
    B {};
};

有谁知道如何继承A::B?


作者: lost_templar    时间: 2014-02-24 22:59
回复 1# eagle518
  1. #include <iostream>
  2. template<typename _A>
  3. struct A
  4. {
  5.     template<typename _B>
  6.     struct B {};
  7. };

  8. template< typename _A, typename _B >
  9. struct C : A<_A>::template B<_B>
  10. {
  11.     C()
  12.     {
  13.         std::cout << "C instance created.\n";
  14.     }

  15. };

  16. int main()
  17. {
  18.     C<int,int> cc;

  19.     return 0;
  20. }
复制代码

作者: 沉水之鱼    时间: 2014-02-25 11:29
回复 2# lost_templar

struct C : A<_A>::template B<_B> 这一句 B前面为什么要加template啊?


   
作者: eagle518    时间: 2014-02-25 19:56
回复 2# lost_templar


    验证通过,

作者: automation_mb    时间: 2014-02-26 08:48
如果限定符::前面的名称依赖于某个模板参数,且后面紧跟一个template-id 就需要加template回复 3# 沉水之鱼


   
作者: 沉水之鱼    时间: 2014-02-26 14:07
回复 5# automation_mb


    谢谢解惑




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2