Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/127.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

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_C++11 - Fatal编程技术网

C++ 模板:使用类类型的成员实例化对象

C++ 模板:使用类类型的成员实例化对象,c++,templates,c++11,C++,Templates,C++11,我有一个创建网格对象的工厂方法。网格对象有一个顶点类成员,该成员可以具有各种风格 template<class T> NewMesh* createMesh(T) { mesh_data* md = new mesh_data; T* vd = new T; md->vdata = vd; NewMesh* mptr = new NewMesh(generateUid()); mpt

我有一个创建网格对象的工厂方法。网格对象有一个顶点类成员,该成员可以具有各种风格

template<class T>
    NewMesh* createMesh(T)
    {
        mesh_data* md = new mesh_data;
        T* vd = new T;
        md->vdata = vd;
        NewMesh* mptr = new NewMesh(generateUid());
        mptr->setData(md);

        return mptr;
    }
很明显,这不起作用,并引发编译时错误

这是可行的,但由于明显的原因(声明一个未使用的变量):


传递类类型的更好方法是什么?

createMesh的函数参数未使用,这强烈表明它是冗余的

template<class T>
    NewMesh* createMesh() { ...


Mesh* polym = meshFactory.createMesh<vertex_data_P3_N3>();
模板
NewMesh*createMesh(){。。。
Mesh*polym=meshFactory.createMesh();

createMesh的功能参数未使用,这强烈表明它是冗余的

template<class T>
    NewMesh* createMesh() { ...


Mesh* polym = meshFactory.createMesh<vertex_data_P3_N3>();
模板
NewMesh*createMesh(){。。。
Mesh*polym=meshFactory.createMesh();
template<class T>
    NewMesh* createMesh() { ...


Mesh* polym = meshFactory.createMesh<vertex_data_P3_N3>();