C++ 获取错误:isoc++;禁止申报‘;键入名称’;没有类型

C++ 获取错误:isoc++;禁止申报‘;键入名称’;没有类型,c++,C++,我有一个嵌套类定义,在对指向它的指针应用强制转换时出错。以下程序编译时出错: test.cpp: In member function ‘void* Achild<T>::test(void*)’: test.cpp:24:31: error: ISO C++ forbids declaration of ‘type name’ with no type [-fpermissive] ShortName::ptr = (const ShortName::Ptr*)inp

我有一个嵌套类定义,在对指向它的指针应用强制转换时出错。以下程序编译时出错:

test.cpp: In member function ‘void* Achild<T>::test(void*)’:
test.cpp:24:31: error: ISO C++ forbids declaration of ‘type name’ with no type [-fpermissive]
       ShortName::ptr = (const ShortName::Ptr*)input;
                               ^~~~~~~~~
test.cpp:24:25: error: expected primary-expression before ‘const’
       ShortName::ptr = (const ShortName::Ptr*)input;
                         ^~~~~
test.cpp:24:25: error: expected ‘)’ before ‘const’
       ShortName::ptr = (const ShortName::Ptr*)input;
                        ~^~~~~
                         )
test.cpp:25:6: warning: no return statement in function returning non-void [-Wreturn-type]
      }
test.cpp:在成员函数“void*Achild::test(void*)”中:
测试:CPP:24:31:错误:ISO C++禁止声明“类型名称”,没有类型[FPrime]。
ShortName::ptr=(常量ShortName::ptr*)输入;
^~~~~~~~~
test.cpp:24:25:错误:“const”之前应为主表达式
ShortName::ptr=(常量ShortName::ptr*)输入;
^~~~~
test.cpp:24:25:error:expected')在“const”之前
ShortName::ptr=(常量ShortName::ptr*)输入;
~^~~~~
)
test.cpp:25:6:警告:返回非void[-Wreturn类型]的函数中没有返回语句
}
我不明白为什么我在第24行出现错误。任何帮助都将不胜感激

template<typename T>
   class VeryLongName
   {
     public:
         class Ptr
         {
                 public:
                         int a;
                         Ptr() = default;
         };
         const Ptr* ptr;

   };

   template <typename T>
   class Achild: public VeryLongName<T>
   {
     using ShortName = VeryLongName<T>;
   public:
     Achild<T>() = default;

     void test(void * input)
     {
             ShortName::ptr = (const ShortName::Ptr*)input;
     }

   };

int main()
{
        auto *achild = new Achild<int>();
        auto a = new VeryLongName<int>::Ptr();
        achild->test((void*)a);
}
模板
类VeryLongName
{
公众:
类Ptr
{
公众:
INTA;
Ptr()=默认值;
};
常数Ptr*Ptr;
};
模板
类名称:public VeryLongName
{
使用ShortName=VeryLongName;
公众:
Achild()=默认值;
无效测试(无效*输入)
{
ShortName::ptr=(常量ShortName::ptr*)输入;
}
};
int main()
{
auto*achild=新achild();
自动a=新的VeryLongName::Ptr();
achild->测试((无效*)a);
}

您缺少
类型名
声明:

ShortName::ptr=(consttypename ShortName::ptr*)输入;

as
ShortName
取决于模板类型。

这将修复它。
ShortName
是否已携带模板类型(
VeryLongName
)?\CaptainJacksparrow
typename
左侧的类类型为从属类型时,需要@CaptainJacksparrow
。使用
X::name
语法是一种常见的方法。使用Z=X将
X
移动到别名
只是意味着
Z
是另一个依赖类型,因此
Z::name
仍然需要
typename