模板指针类型.... [英] Template Pointer Type....

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

问题描述

Hello Folks ...


只需浏览模板......找到一个值得分享的好问题


C ++允许语法类型


模板< class T>

T * ptr;


这个ptr可以用来指向类型,如int变量或浮点变量


ex:int i = 10;

ptr =& i;


如果可以这样做,请分享这样做的语法...

评论将不胜感激。 ..

Hello Folks...

Just going through the templates... found one good question worth sharing

C++ allows the syntax type

template <class T>
T * ptr;

can this ptr be used to point to types likes int variable or float variable

ex: int i =10;
ptr = &i;

If this can be done plz share the syntax of doing it...
Comments will be appreciated...

推荐答案




我不太确定你在找什么..但是反正......

* ptr可以指出T对象,T对象可以是int,float或者只要你在使用模板时指定它就可以了。


/ MK
Hi,

I''m not quite sure what you''re looking for here...but anyways...
The *ptr can point out T-objects, the T object can be an int, float or Whatever just as long as you specify it when you use the template.

/MK






我我不太确定你在这里寻找什么......但无论如何......

* ptr可以指出T对象,T对象可以是int,float或者只要你在使用模板时指定就行了。


/ MK
Hi,

I''m not quite sure what you''re looking for here...but anyways...
The *ptr can point out T-objects, the T object can be an int, float or Whatever just as long as you specify it when you use the template.

/MK



Hello .... br />
你能不能我是如何做到这一点的语法...

i已创建

模板< class T>

T * ptr;


main()

{

int i = 10;

//这里我要分配i到ptr&的地址使用ptr显示值


float j = 20.23;

//这里我想将j的地址分配给ptr&使用ptr显示值


返回0;

}

Hello ....
Can you just give me the syntax of how to do that ...
i have created
template <class T>
T * ptr;

main()
{
int i =10;
//Here i want to assign the address of i to ptr & display value using ptr

float j = 20.23;
//here i want to assing the address of j to ptr & display value using ptr

return 0;
}





查看链接。


/ MK
Hi,

Check out this link.

/MK


这篇关于模板指针类型....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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