Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 从成员函数返回模板类_C++_Templates - Fatal编程技术网

C++ 从成员函数返回模板类

C++ 从成员函数返回模板类,c++,templates,C++,Templates,我正在尝试使用ECS模式实现引擎,我希望使用实体类模板来表示游戏中的对象: template<typename...components> class entity { //... }; 模板 类实体 { //... }; 和实体管理器类,用于管理实体的生存期: class entity_manager { public: template<typename...components> entity<components...> c

我正在尝试使用ECS模式实现引擎,我希望使用实体类模板来表示游戏中的对象:

template<typename...components>
class entity
{
    //...
};
模板
类实体
{
//...
};
和实体管理器类,用于管理实体的生存期:

class entity_manager
{
public:
    template<typename...components>
    entity<components...> create_entity<components...>();
    
    bool destroy_entity(entity_id id);
    //...
}
类实体\u管理器
{
公众:
模板
实体创建_实体();
bool销毁实体(实体id);
//...
}
当我试图编译它时,gcc出现以下错误:

error: expected initializer before ‘<’ token
   15 |     entity<components...> create_entity<components...>();
      |                                        ^

错误:在“之前应该有初始值设定项。在声明中,没有将模板参数列表放在函数名之后

简单地说:

template<typename...components>
entity<components...> create_entity();
模板
实体创建_实体();

在函数声明中
创建_实体()-->
创建实体()否则它看起来像一个专门化。
template<typename...components>
entity<components...> create_entity();