为什么c ++不支持typeof()? [英] why c++ not support typeof()?

查看:793
本文介绍了为什么c ++不支持typeof()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好


Q1:


在阅读STL的源代码时,我只是对为什么c ++不支持感到困惑

这样的pesudo代码?


// pesudo代码

int a = new int()£?

Typeof(a)b = new Typeof(a)()£?

Q2£o


不是关于c ++:


如何阅读较旧的帖子? 2002年的一些写作样本?

我试过谷歌,没有运气。


谢谢。


你的密钥9

Hi all

Q1:

On reading source code of STL, I just confuse about why c++ not support
such a pesudo code ?

//pesudo code
int a = new int()£?
Typeof(a) b = new Typeof(a)()£?
Q2£o

NOT about c++:

How to read older post? for sample some one write on year 2002?
I tried google , no lucky.

thank you .

your key9

推荐答案

不像java,任何人都不能知道真正的类型与

对象有关运行时间。

思考无效,输入类型等。


" void"可以收到所有类型。

" type casting"可以有很多不同的类型。

Not like java, Anyone CAN NOT not know the realy type to be related an
object at the run time.
Think "void", "type casting", etc.

"void" can receive all of type.
"type casting" can many different type.


Key9写道:
大家好

Q1:
在阅读STL的源代码时,我只是混淆了为什么c ++不支持这样的pesudo代码?

// pesudo代码
int a = new int ()£?
Typeof(a)b = new Typeof(a)()£?


因为C ++是静态类型的。


你可以在运行时用虚拟

产生类似的效果构造"或工厂方法习语。


您可以使用

模板生成静态绑定的类似效果。


Q2£o

不是关于c ++:


那么让我们来讲解C ++。

如何阅读较旧的帖子? 2002年的一些写作样本?
我试过谷歌,没有幸运。
Hi all

Q1:

On reading source code of STL, I just confuse about why c++ not support
such a pesudo code ?

//pesudo code
int a = new int()£?
Typeof(a) b = new Typeof(a)()£?
Because C++ is statically typed.

You can produce similar effects at runtime with the "virtual
constructor" or factory method idioms.

You can produce similar effects which are statically bound, by using
templates.

Q2£o

NOT about c++:
Well then lets make it about C++.
How to read older post? for sample some one write on year 2002?
I tried google , no lucky.




你的意思是,你如何阅读comp.lang的存档帖子。 c ++?

http:// groups。 google.com/group/comp.lang.c++


Ben Pope

-

我''我不只是一个数字。对很多人来说,我被称为弦乐......



You mean, how do you read archived posts of comp.lang.c++?

http://groups.google.com/group/comp.lang.c++

Ben Pope
--
I''m not just a number. To many, I''m known as a string...


Key9写道:
大家好

Q1:

在阅读STL的源代码时,我只是混淆了为什么c ++不支持
这样的pesudo代码?

// pesudo代码
int a = new int();
Typeof(a)b = new Typeof(a)();
Hi all

Q1:

On reading source code of STL, I just confuse about why c++ not support
such a pesudo code ?

//pesudo code
int a = new int();
Typeof(a) b = new Typeof(a)();




1998年没有提案什么时候引入C ++ 98。它可能会在下一个版本中出现

,尽管可能是另一个名字。 (decltype,

IIRC,因为

'*'*'''''''''''''''''''''''''''''' />
当然,如果编译器有STL实现,可以利用

实现

并使用__typeof。


HTH,

Michiel Salters



There was no proposal for this in 1998 when C++98 was introduced. It
may appear
in the next version, although probably by another name. (decltype,
IIRC, because
it''s the *declared* type of ''a'' that determines decltype(a))

Of course, an STL implementation make take advantage of the
implementation
and use __typeof today, if the compiler has it.

HTH,
Michiel Salters


这篇关于为什么c ++不支持typeof()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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