Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2027584
  • 博文数量: 414
  • 博客积分: 10312
  • 博客等级: 上将
  • 技术积分: 4921
  • 用 户 组: 普通用户
  • 注册时间: 2007-10-31 01:49
文章分类

全部博文(414)

文章存档

2011年(1)

2010年(29)

2009年(82)

2008年(301)

2007年(1)

分类: C/C++

2009-02-17 09:02:57

情况一:
   func1(string & str);
      
   a) func1(string("hello"));                    编译错误
   b) string s1 = string("hello"); func1(s1);    编译通过

情况二:
   func2(string str)
   a) func1(string("hello"));                    编译通过
   b) string s1 = string("hello"); func1(s1);    编译通过


原因
1 string("hello")等同于常量,不能传递给引用参数
2 引用传递的参数要求是可以进出的,也就是说目的是高效传递一个参数,并且要求这个参数是可以返回的
  如果使用匿名传递的方式,参数就等于传递丢失了,传递丢失的东西是找不回来的,匿名也就自然不会对。
  这里要先对变量进行命名,然后再传递给应用参数
 
阅读(1296) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~