相关疑难解决方法(0)

如何在类中创建模板函数?(C++)

我知道可以制作模板功能:

template<typename T>
void DoSomeThing(T x){}
Run Code Online (Sandbox Code Playgroud)

并且可以创建模板类:

template<typename T>
class Object
{
public:
    int x;
};
Run Code Online (Sandbox Code Playgroud)

但是可以创建一个不在模板中的类,然后在该类中创建一个模板的函数吗?即:

//I have no idea if this is right, this is just how I think it would look
class Object
{
public:
    template<class T>
    void DoX(){}
};
Run Code Online (Sandbox Code Playgroud)

或类似的程度,类不是模板的一部分,但功能是?

c++ templates class function

140
推荐指数
4
解决办法
15万
查看次数

标签 统计

c++ ×1

class ×1

function ×1

templates ×1