| 
					阅读:1551回复:3
				 关于引用的这种用法正确吗?
					假如SimpleCat是一个已经定义了copy constructor的类,那么能否定义如下的函数?
 SimpleCat FunctionFour(SimpleCat &theCat) { .........; return theCat; } 我已经实验过,以下几种函数的定义方法完全正确: SimpleCat FunctionOne(SimpleCat theCat) { .........; return theCat; } 或者: SimpleCat *FunctionTwor(SimpleCat *theCat) { .........; return theCat; } 或者: SimpleCat &FunctionThree(SimpleCat &theCat) { .........; return theCat; } 而且,FunctionOne,FunctionTwo, FunctionThree, FunctionFour 都可以实现相同的结果. 但是,我没有看见FunctionFour的这种用法,请问,这种用法正确吗? | |
| 沙发#发布于:2004-10-28 09:15 
					我在昨天看书时也发现了下述使用方法.这说明是可以这样用的.
 SimpleCat FunctionFour(SimpleCat &theCat) { .........; return theCat; } | |
| 板凳#发布于:2004-10-23 19:06 
					SimpleCat FunctionFour(SimpleCat &theCat)
 { .........; return theCat; } 这个函数返回后最好不要这样使用 youcat = FunctionFour( youcat ); 因为当函数返回前 youcat 已经有结果了,除非把这个返回值给别的变量或对象 youcat2 = FunctionFour( youcat1 ); 所以,如果只给一个对象操作尽量使用 void FunctionFour(SimpleCat &theCat) { ………… } | |
| 地板#发布于:2004-10-23 13:29 
					这几种语法应该都是对的
 本人认为C++里,效率最高的应该是 void FunctionFour(SimpleCat &theCat) { .........; } | |
| 
 | 
 
							
 
				 
				