程序代码:
#include <iostream> double foo( const std::initializer_list<double>& bs ) { if( bs.size() == 0 ) return 0; auto itor = std::rbegin(bs); double x = *itor;; for( ++itor; itor!=std::rend(bs); ++itor ) x = 1/x + *itor; return x; } int main( void ) { double x1 = foo( {1} ); std::cout << x1 << std::endl; double x2 = foo( {1,2} ); std::cout << x2 << std::endl; double x3 = foo( {1,2,3} ); std::cout << x3 << std::endl; double x4 = foo( {0,0} ); std::cout << x4 << std::endl; return 0; }