【问题标题】:Making a template based on an internal class基于内部类制作模板
【发布时间】:2014-03-24 22:09:32
【问题描述】:

我正在尝试创建一个在其内部定义的类之一上模板化的类。

我认为通过转发声明相关类,我会没事的。
但我不断收到编译时错误,例如:

use of undefined type QueryGetCustomer
Reply uses undefined class QueryGetCustomer

当类ReplyQueryCustomer 的内部时,有什么方法可以在Reply 上模板QueryGetCustomer,如这段代码所示?

class QueryGetCustomer;
class QueryGetCustomer::Reply; // error: use of undefined type QueryGetCustomer
                               // error: Reply uses undefined class QueryGetCustomer

class QueryGetCustomer :
   public BaseQuery<QueryGetCustomer::Reply>
{
public:
    class Reply { [....] };
};

附:当 Reply 类是 QueryGetCustomer 类的外部(全局)时,我有这个模板结构工作。

但是,Reply 仅在 Query 中才真正有意义,所以我真的很想将它作为一个内部类。

【问题讨论】:

    标签: c++ oop templates inheritance


    【解决方案1】:

    尝试转发声明内部类时整个事情都失败了。

    您不能转发声明类的内部类型。就是这样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-28
      • 1970-01-01
      • 2015-11-14
      • 1970-01-01
      • 2018-05-06
      • 1970-01-01
      相关资源
      最近更新 更多