foobar

  C++博客 :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理 ::
  6 随笔 :: 14 文章 :: 0 评论 :: 0 Trackbacks

 

 1 # include <iostream.h>
 2 void output( int x); // 函数声明
 3 void output( float x); // 函数声明
 4 void output( int x)
 5 {
 6 cout << " output int " << x << endl ;
 7 }
 8 void output( float x)
 9 {
10 cout << " output float " << x << endl ;
11 }
12 void main(void)
13 {
14 int x = 1;
15 float y = 1.0;
16 output(x); // output int 1
17 output(y); // output float 1
18 output(1); // output int 1
19 // output(0.5); // error! ambiguous call, 因为自动类型转换
20 output(int(0.5)); // output int 0
21 output(float(0.5)); // output float 0.5
22 }
posted on 2007-11-23 20:35 foobar 阅读(388) 评论(0)  编辑 收藏 引用

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理