bool f() { 如果(!pointer1)返回false; pointer1-> doSomething(); if(!pointer2)返回false; pointer2-> doSomething1(); 返回true ; } vs. bool f() { bool retVal = true; if(pointer1) { pointer1-> doSomething(); } 其他 retVal = false; if(pointer2) { pointer2-> doSomething(); } else retVal = false; 返回retVal; } >A colleague told me that there is a rule about good stype that afunction in C++ should have only one point of return (ie. returnstatement). Otherwise there might be trouble.I never heard about it and doubt it.Anybody heard of it? What would be the advantage?Regards,MarcExample:bool f(){if( !pointer1) return false;pointer1->doSomething();if( !pointer2) return false;pointer2->doSomething1();return true;}vs.bool f(){bool retVal=true;if( pointer1){pointer1->doSomething();}elseretVal=false;if( pointer2){pointer2->doSomething();}elseretVal=false;return retVal;} 第二个例子不同于第一个例子 它会转到指针2部分,即使指针1不存在。 每个人都有一个意见,但是在C ++中有IMO,维持 a单身入口点导致更多混淆代码 而不是更少(这是,我相信, 支持它的论点。) This second example is different than the first sinceit goes to the pointer2 part even if pointer1 doesn''texist.Everyone has an opinion but IMO in C++, maintaininga single entry point leads to more obfuscated coderather than less (which is, I believe, the argument infavor of it.) " duane hebert" < sp ** @flarn.comwrote in message news:9p ******************** @ weber.videotron.net .. 。 "duane hebert" <sp**@flarn.comwrote in messagenews:9p********************@weber.videotron.net... 第二个例子与第一个例子不同,因为 即使指针1不是 存在。 每个人都有意见,但IMO在C ++中,保持单个入口点a导致更多混淆代码 This second example is different than the first sinceit goes to the pointer2 part even if pointer1 doesn''texist.Everyone has an opinion but IMO in C++, maintaininga single entry point leads to more obfuscated code a单出口点(duh) a single exit point (duh) 这篇关于只有一点回报的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 11-03 06:01