class armon
{
static const int maxSize=10;
int array[maxSize];
int count=0;
int* topOfStack=array;
}
Run Code Online (Sandbox Code Playgroud)
为什么maxSize需要static在数组中使用它?
#include <iostream>
using namespace std;
class armon {
int a;
int b;
public:
armon(int newA, int newB) : a(newA), b(newB) {}
armon setA(int newA) {
a = newA;
return *this;
}
armon setB(int newB) {
b = newB;
return *this;
}
void print(void) { cout << a << endl << b; }
};
int main() {
armon s(3, 5);
s.setA(8).setB(9);
s.print();
}
Run Code Online (Sandbox Code Playgroud)