C++ C++;模板类编译错误消息:错误:在';typename';

C++ C++;模板类编译错误消息:错误:在';typename';,c++,templates,compiler-errors,llvm,C++,Templates,Compiler Errors,Llvm,我正试图从中编译代码 我正在使用LLVMs em++编译器进行编译: em++:版本1.3.2 叮当声:vesion 3.6.0 以下是控制台错误消息: /opt/emsdk_portable/emscripten/master/em++ -Qunused-arguments -U__STRICT_ANSI__ -Wall -fno-strict-aliasing -std=c++11 -DAS_WRITE_OPS=0 -DAS_USE_STLNAMES=1 -DAS_USE_FLOAT=0

我正试图从中编译代码

我正在使用LLVMs em++编译器进行编译:

  • em++:版本1.3.2
  • 叮当声:vesion 3.6.0
以下是控制台错误消息:

/opt/emsdk_portable/emscripten/master/em++ -Qunused-arguments -U__STRICT_ANSI__ -Wall -fno-strict-aliasing -std=c++11 -DAS_WRITE_OPS=0 -DAS_USE_STLNAMES=1 -DAS_USE_FLOAT=0 -Iinclude/ -Iangelscript/sdk/angelscript/include/ -Iangelscript/sdk/add_on/scriptbuilder/ -Iangelscript/sdk/add_on/contextmgr/ -Iangelscript/sdk/add_on/scripthelper/ -Iangelscript/sdk/add_on/scriptany/ -Iangelscript/sdk/add_on/scriptstdstring/ -Iangelscript/sdk/add_on/scriptdictionary/ -Iangelscript/sdk/add_on/scriptarray/ -Iangelscript/sdk/add_on/scriptmath/ -Iangelscript/sdk/add_on/scriptgrid/  -c aatc/source/aatc_registration_tempspecs.cpp  -o aatc/source/aatc_registration_tempspecs.o
In file included from aatc/source/aatc_registration_tempspecs.cpp:40:
In file included from aatc/source/aatc_tempspecs.hpp:37:
aatc/source/aatc_shared_tempspec.hpp:52:11: error: expected a qualified name after 'typename'
        typename typedef T_container::iterator iteratortype;
                 ^
aatc/source/aatc_shared_tempspec.hpp:52:11: error: expected member name or ';' after declaration specifiers
        typename typedef T_container::iterator iteratortype;
                 ^
aatc/source/aatc_shared_tempspec.hpp:97:18: error: cannot specialize a function 'Push_Back' within class scope
        template<> void Push_Back<aatc_Y>(const T_content& value){
                        ^
aatc/source/aatc_shared_tempspec.hpp:101:18: error: cannot specialize a function 'Pop_Back' within class scope
        template<> void Pop_Back<aatc_Y>(){
                        ^
aatc/source/aatc_shared_tempspec.hpp:106:25: error: cannot specialize a function 'Register_func_back_write' within
      class scope
        template<> static void Register_func_back_write<aatc_Y>(asIScriptEngine* engine, int& r, char* text...
                               ^
aatc/source/aatc_shared_tempspec.hpp:114:24: error: cannot specialize a function 'Back' within class scope
        template<> T_content& Back<aatc_Y>(){
                              ^
aatc/source/aatc_shared_tempspec.hpp:119:25: error: cannot specialize a function 'Register_func_back_read' within
      class scope
        template<> static void Register_func_back_read<aatc_Y>(asIScriptEngine* engine, int& r, char* textb...
                               ^
aatc/source/aatc_shared_tempspec.hpp:126:18: error: cannot specialize a function 'Push_Front' within class scope
        template<> void Push_Front<aatc_Y>(const T_content& value){
                        ^
aatc/source/aatc_shared_tempspec.hpp:130:18: error: cannot specialize a function 'Pop_Front' within class scope
        template<> void Pop_Front<aatc_Y>(){
                        ^
aatc/source/aatc_shared_tempspec.hpp:135:25: error: cannot specialize a function 'Register_func_front_write' within
      class scope
        template<> static void Register_func_front_write<aatc_Y>(asIScriptEngine* engine, int& r, char* tex...
                               ^
aatc/source/aatc_shared_tempspec.hpp:143:24: error: cannot specialize a function 'Front' within class scope
        template<> T_content& Front<aatc_Y>(){
                              ^
aatc/source/aatc_shared_tempspec.hpp:148:25: error: cannot specialize a function 'Register_func_front_read' within
      class scope
        template<> static void Register_func_front_read<aatc_Y>(asIScriptEngine* engine, int& r, char* text...
                               ^
aatc/source/aatc_shared_tempspec.hpp:167:18: error: cannot specialize a function 'Erase_value' within class scope
        template<> void Erase_value<aatc_Y>(const T_content& value){
                        ^
aatc/source/aatc_shared_tempspec.hpp:172:25: error: cannot specialize a function 'Register_func_erase_value' within
      class scope
        template<> static void Register_func_erase_value<aatc_Y>(asIScriptEngine* engine, int& r, char* tex...
                               ^
aatc/source/aatc_shared_tempspec.hpp:180:24: error: cannot specialize a function 'op_index' within class scope
        template<> T_content& op_index<aatc_Y>(aatc_type_sizetype index){
                              ^
aatc/source/aatc_shared_tempspec.hpp:186:25: error: cannot specialize a function 'Register_func_op_index' within
      class scope
        template<> static void Register_func_op_index<aatc_Y>(asIScriptEngine* engine, int& r, char* textbu...
                               ^
aatc/source/aatc_shared_tempspec.hpp:192:18: error: cannot specialize a function 'Reserve' within class scope
        template<> void Reserve<aatc_Y>(aatc_type_sizetype count){
                        ^
aatc/source/aatc_shared_tempspec.hpp:197:25: error: cannot specialize a function 'Register_func_reserve' within
      class scope
        template<> static void Register_func_reserve<aatc_Y>(asIScriptEngine* engine, int& r, char* textbuf...
                               ^
aatc/source/aatc_shared_tempspec.hpp:203:18: error: cannot specialize a function 'Insert' within class scope
        template<> void Insert<aatc_Y>(const T_content& value){
                        ^
fatal error: too many errors emitted, stopping now [-ferror-limit=]
20 errors generated.
/opt/emsdk_-portable/emscripten/master/em++-常用参数-U_uu-STRICT\U-ANSI_uu-Wall-fno-STRICT别名-std=c++11-DAS_-WRITE_-OPS=0-DAS_-USE_-STLNAMES=1-DAS_-USE_-FLOAT=0-Iinclude/-Iangelscript/sdk/angelscript/include/-Iangelscript/sdk/add-on/scriptbuilder/-Iangelscript/sdk/add/add-on/contextmgr/-Iangelscript/sdk/script-Iangelscript/sdk/add_on/scriptany/-Iangelscript/sdk/add_on/ScriptString/-Iangelscript/sdk/add_on/scriptdictionary/-Iangelscript/sdk/add_on/scriptmath/-Iangelscript/sdk/add_on/scriptgrid/-c aatc/source/aatc_registration\u tempspecs.cpp-o aatc/source/aatc_registration\u tempspecs.o
在aatc/source/aatc_registration_tempspecs.cpp:40中包含的文件中:
在aatc/source/aatc_tempspecs.hpp:37中包含的文件中:
aatc/source/aatc_shared_tempspec.hpp:52:11:错误:在“typename”之后应该有一个限定名
typename typedef T_容器::迭代器迭代器类型;
^
aatc/source/aatc_shared_tempspec.hpp:52:11:错误:应为成员名或“;”后声明说明符
typename typedef T_容器::迭代器迭代器类型;
^
aatc/source/aatc_shared_tempspec.hpp:97:18:错误:无法在类范围内专门化函数“Push_Back”
模板无效推回(常量内容和值){
^
aatc/source/aatc_shared_tempspec.hpp:101:18:错误:无法在类范围内专门化函数“Pop_Back”
模板void Pop_Back(){
^
aatc/source/aatc_shared_tempspec.hpp:106:25:错误:无法在中专门化函数“Register_func_back_write”
类范围
模板静态无效寄存器函数回写(asIScriptEngine*引擎,int&r,字符*文本。。。
^
aatc/source/aatc_shared_tempspec.hpp:114:24:错误:无法在类范围内专门化函数“Back”
模板T_内容和背面(){
^
aatc/source/aatc_shared_tempspec.hpp:119:25:错误:无法在中专门化函数“Register_func_back_read”
类范围
模板静态无效寄存器\u func\u back\u read(asIScriptEngine*engine,int&r,char*textb。。。
^
aatc/source/aatc_shared_tempspec.hpp:126:18:错误:无法在类范围内专门化函数“Push_Front”
模板无效推送前端(常量内容和值){
^
aatc/source/aatc_shared_tempspec.hpp:130:18:错误:无法在类范围内专门化函数“Pop_Front”
模板void Pop_Front(){
^
aatc/source/aatc_shared_tempspec.hpp:135:25:错误:无法在中专门化函数“Register\u func\u front\u write”
类范围
模板静态无效寄存器函数前写(asIScriptEngine*engine,int&r,char*tex。。。
^
aatc/source/aatc_shared_tempspec.hpp:143:24:错误:无法在类范围内专门化函数“Front”
模板T_内容和前端(){
^
aatc/source/aatc_shared_tempspec.hpp:148:25:错误:无法在中专门化函数“Register\u func\u front\u read”
类范围
模板静态无效寄存器\u func\u front\u read(asIScriptEngine*引擎,int&r,字符*文本。。。
^
aatc/source/aatc_shared_tempspec.hpp:167:18:错误:无法在类范围内专门化函数“Erase_value”
模板无效擦除值(常量内容和值){
^
aatc/source/aatc_shared_tempspec.hpp:172:25:错误:无法在中专门化函数“Register_func_erase_value”
类范围
模板静态无效寄存器函数擦除值(asIScriptEngine*engine,int&r,char*tex。。。
^
aatc/source/aatc_shared_tempspec.hpp:180:24:错误:无法在类范围内专门化函数“op_index”
模板内容和操作索引(aatc类型大小索引){
^
aatc/source/aatc_shared_tempspec.hpp:186:25:错误:无法在中专门化函数“Register_func_op_index”
类范围
模板静态无效寄存器函数操作索引(asIScriptEngine*engine,int&r,char*textbu。。。
^
aatc/source/aatc_shared_tempspec.hpp:192:18:错误:无法在类范围内专门化函数“Reserve”
模板无效保留(aatc\U类型\U大小类型计数){
^
aatc/source/aatc_shared_tempspec.hpp:197:25:错误:无法在中专门化函数“Register_func_reserve”
类范围
模板静态无效寄存器功能保留(asIScriptEngine*engine,int&r,char*textbuf。。。
^
aatc/source/aatc_shared_tempspec.hpp:203:18:错误:无法在类范围内专门化函数“Insert”
模板无效插入(常量内容和值){
^
致命错误:发出的错误太多,正在停止[-ferror limit=]
产生了20个错误。

如何解决此问题?

typename
typedef
的顺序颠倒,应该是:

typedef typename T_container::iterator iteratortype;
这是因为
typename
修饰了限定名
T_container::iterator
,而整个修饰的东西就是
typedef
的主题

其他错误的主机是非常自我解释的:代码显然包含了在类内声明的模板特化,这不是合法的C++。

class X
{
  template <class T>
  void Erase_value(const T_content& value);

  template <>
  void Erase_value<aatc_Y>(const T_content& value){ /* ... */ }
};
class X
{
  template <class T>
  void Erase_value(const T_content& value);
};

template <>
void X::Erase_value<aatc_Y>(const T_content& value){ /* ... */ }
X类
{
样板
无效擦除值(常量内容和值);
样板
无效擦除值(常量内容和值){/*…*/}
};
一定是这样