typeof和g ++ [英] typeof and g++
问题描述
你好,
g ++'s typeof是一个非常有用的功能!
它是否永远不会出现在标准中?
是有没有合适的方式来实现它?
如果我的意思是一个函数模板返回一个类型,也许这个
不可能?
什么''关于g ++的类型实现;怎么样?
内部工作?
谢谢。
-
fabioppp
Hi there,
g++''s typeof is a very useful feature!
Will it never be in the Standard?
Is there any compliant way to implement it?
If I mean a function template returning a type, maybe is this
impossible?
What''s about g++''s typeof implementation; how does it
work internally?
Thank.
--
fabioppp
推荐答案
> g ++'s typeof是一个非常有用的功能!
你能举一个例子说明你使用它吗?
我想不出任何否则无法解决的情况。
- John
> g++''s typeof is a very useful feature!
Could you please give an example where you use it?
I can''t think of any scenario which can''t be solved otherwise.
-- John
John Smith写道:
John Smith wrote:
g ++'s typeof是一个非常有用的功能!
g++''s typeof is a very useful feature!
你能举一个例子说明你使用它吗?
我可以我想不出任何其他情况都无法解决的问题。
- 约翰
Could you please give an example where you use it?
I can''t think of any scenario which can''t be solved otherwise.
-- John
模板功能推导出一个类型,然后返回一些值。我有
来知道返回值的类型。
如果我使用sizeof的一些技巧,我想我可以避免使用typeof。
但是在这种情况下很难以某种方式使用sizeof。
-
Fabio
A template function deduce a type, and then return some values. I have
to know the type of the returned value.
If I use some trick with sizeof I think I could avoid the use of typeof.
But in this situation is really difficult to use sizeof in some way.
--
Fabio
>
fabioppp写道:
fabioppp wrote:
模板函数推导出一种类型,然后返回一些值。我知道返回值的类型。
如果我使用sizeof的一些技巧我认为我可以避免使用typeof。
但是在这种情况下使用sizeof真的很难以某种方式。
A template function deduce a type, and then return some values. I have
to know the type of the returned value.
If I use some trick with sizeof I think I could avoid the use of typeof.
But in this situation is really difficult to use sizeof in some way.
对于运行时类型识别(RTTI),标准C ++提供了
dynamic_cast。对于扩展类型信息,它提供了typeid。
TC ++ PL的第15章涵盖了这些内容。来自那里的剪辑:
" dynamic_cast运算符在运行时满足大多数关于对象的b / b $ b类型信息的需求。重要的是,它确保使用它编写的代码可以正确地使用从程序员提到的明确
派生的类。因此,dynamic_cast以类似于虚函数的方式保留了灵活性和可扩展性。
但是,有时必须知道确切的类型。 />
对象。例如,我们可能想知道对象的名称?
类或其布局。 typeid运算符通过产生
表示其操作数类型的对象来实现此目的。
-
Ioannis Vranos
http://www23.brinkster.com/noicys
这篇关于typeof和g ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!