
思路:在新类中使用全局变量进行运算,在主类中定义新类数组,通过构造函数的调用次数返回阶乘
#include <type_traits>
class add{public:static int count;static int tmp;add(){count=count+tmp;tmp++;}
};
int add::count=0;
int add::tmp=1;
class Solution {
public:int Sum_Solution(int n) {add a[n];return add::count;}
};