【问题标题】:How to include a templated typefef of a structure in a structure如何在结构中包含结构的模板化 typefef
【发布时间】:2014-08-03 15:11:41
【问题描述】:

我正在尝试在同一类型结构中包含一个模板化的(类型结构的)typedef。编译器抱怨找不到 typedef 或结构,具体取决于我将它们放在头文件中的顺序。

示例 1(./RobotControl.h:25:23: 错误:“InputUpdate_S”未在此范围内声明)

class RobotControl
{
public:
  SomeFunctions();

  typedef Functor1<InputUpdate_S> InputUpdateFunctor_T;

   struct InputUpdate_S
   {
      InputUpdateType_E UpdateType;
      UInt8_T CoProcNum;
      UInt8_T PinNum;
      InputUpdateFunctor_T *callback;
   };
};

Example2(错误:‘InputUpdateFunctor_T’没有命名类型)

class RobotControl
{
public:
  SomeFunctions();

   struct InputUpdate_S
   {
      InputUpdateType_E UpdateType;
      UInt8_T CoProcNum;
      UInt8_T PinNum;
      InputUpdateFunctor_T *callback;
   };

   typedef Functor1<InputUpdate_S> InputUpdateFunctor_T;

};

我该如何解决这个问题?

【问题讨论】:

    标签: c++ struct typedef


    【解决方案1】:

    您可以通过在 typedef 之前前向声明 InputUpdate_S(即写 struct InputUpdate_S;)来修复它,或者在 InputUpdate_S 中不使用 typedef 而是写 Functor1&lt;InputUpdate_S&gt; *callback;

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-12-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多