在下面的代码中,updateWithContex返回与参数相同的对象是不是很糟糕?
class SomeClass{ Foo updateWithContex(Foo foo){ foo.setAppId(i); foo.setXId(index); //..... return foo; } } class Foo{ public void setAppId(int appId) { // } public void setXId(int appId) { // } public void changeState(X x) { // } }
在C中,我看到过这样的代码:
BigObject& fastTransform( BigObject& myBO ) { // When entering fastTransform(),myBO is the same object as the function // argument provided by the user. -> No copy-constructor is executed. // Transform myBO in some way return myBO; // Transformed myBO is returned to the user. }
这也错了吗?