标签:end int cpp void pop class sizeof ati let
不使用if, while,for,switch等实现从1到10的加法
解:这里使用静态函数和静态变量实现,利用类似的方法也能够实现从1打印到1000
class TheSum{ public: TheSum(); static int GetSum(); private: static int N; static int sum; }; int TheSum::N=0; int TheSum::sum=0; int TheSum::GetSum() { return sum; } TheSum::TheSum() { N++; sum+=N; } int caculateSum(int n) { TheSum *p=new TheSum[n]; int sum=TheSum::GetSum(); delete p; return sum; } #define MMySizeOf(value) ((char *)(&value+1) - (char *)&value) void main() { cout<<caculateSum(10)<<endl; }
标签:end int cpp void pop class sizeof ati let
原文地址:http://www.cnblogs.com/yangykaifa/p/7221843.html