使用内部类可以使程序的封装性更加完美 #include <type_traits>class Solution {class add{public:static int count;static int tmp;add(){count=count+tmp;tmp++;} }; public:int Sum_Solution(int n) {add a[n];return add::count;} };int Solution::add::count=0; int Solution::add::tmp=1;