问题描述
我在informit.com上发现了一篇关于C ++演员的文章
奇怪的是作者说下面的代码将*不*
编译:
double d = 15.95;
int n = static_cast< int(d);
然后他继续对C ++演员发起攻击。我看不出
为什么它不能工作的任何原因我尝试使用MS和INTEL
编译器并且编译时没有问题。 />
有谁知道他想说的是什么???
欢呼,
/ Charles
Hi,
I found an article on informit.com that talks about C++ casts
http://www.informit.com/guides/conte...eqNum=285&rl=1
The strange thing is the author says the following code will *not*
compile:
double d=15.95;
int n= static_cast<int(d);
and then he goes on to launch an attack against C++ casts. I can''t see
any reason why it shouldn''t work and I tried with the MS and INTEL
compilers and it compiles with nary a problem.
Does anyone know what he''s trying to say???
cheers,
/Charles
推荐答案
我几乎可以肯定作者试图说:C ++很糟糕,我最喜欢
语言更好
-
Salu2
I''m almost sure that the author tries to say: "C++ sucks, my favorite
language is better"
--
Salu2
语言更好
-
Salu2
language is better"
--
Salu2
< ; grinWell我会同意你的意见,但他是C ++的家伙。即使是在C ++标准委员会任职,他也是b $ b。所以这似乎是一个奇怪的错误。
<grinWell I would agree with you normally but he''s a C++ guy. He''s
even served on the C++ standards committee. So it seems to be a strange
mistake to make.
我实际找到的代码是:
int n;
double d = 15.95;
int n = static_cast< int(d);
由于变量n被定义两次而无法编译。删除了n的第一个定义后,代码编译得很好并做了它应该做的事情。
The code I actually found there was:
int n;
double d=15.95;
int n= static_cast<int(d);
which won''t compile as the variable n is defined twice. Having removed
the first definition of n, the code compiles fine and does what it should.
显然他对这些事情一无所知,并且懒得在他的教科书中查看
。
Obviously he doesn''t know anything about them and won''t bother to look
into his textbook.
不。忽略他。
问候,
Stuart
Nope. Ignore him.
Regards,
Stuart
这篇关于关于C ++演员的奇怪文章的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!