具有用户定义数据类型参数的模板类。 [英] Template class having a parameter of user defined data type.

查看:73
本文介绍了具有用户定义数据类型参数的模板类。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

== 大家好,



我想创建一个类模板,它能够接受用户定义的数据类型一个参数。



例如:



模板< class t =>

类MyClass

{

};



现在我要创建另一个class,

ie



class sample

{

};

和MyClass应该能够接受样本类作为输入参数。







提前谢谢

==Hi All,

I want to create a class template, which is able to accept a user defined data type as a parameter.

for eg:

template <class t="">
class MyClass
{
};

now i want to create a another class,
ie

class sample
{
};
and MyClass should able to accept the sample class as a input parameter.



Thanks in advance

推荐答案

模板代码需要理解示例类的内容...您需要#include示例类标题包含MyClass的文件(以及'模板类MyClass'语句之前)。



您还可以在头文件末尾添加MyClass定义以获取样本(即。定义样本后)。
The template code needs to "understand" what the sample class is... you will need to #include the sample class header in the file containing MyClass (and before the 'template class MyClass' statement).

You could also add the MyClass definition at the end of the header file for sample (ie. after sample is defined).


这篇关于具有用户定义数据类型参数的模板类。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆